image positions on jquery
Hello Friends I have a website. In this I want the logo image will be like same on home page but in other pages it will be go towards the up and only the name will be seen not the whole logo image. So how to do that in jQuery? Any advic开发者_Python百科e will be highly appreciable.
You don't need to use javascript, just change it from position:absolute
to position:fixed
. (If IE <7 support is needed, there's workarounds for bugs in position:fixed).
UPDATE (See Comments)
Based on my understanding of what you're trying to accomplish from the comment string below, try this:
$(document).ready(function() {
$('ul.menu li a').each(function() {
$(this).click(function() {
$('#logo').css('top', $($(this).attr('href')).offset().top);
setTimeout("$('#logo').fadeIn('slow');", 600);
});
if ($(this).hasClass('selected'))
$(this).click();
});
});
I got it. It will be like this
<script type="text/javascript">
if(jQuery(window).scrollTop() > 0) {
jQuery('h1#logo').css({
top: '-85px'
});
}
jQuery(window).scroll(function() {
if(jQuery(this).scrollTop() > 0) {
jQuery('h1#logo').clearQueue();
jQuery('h1#logo').animate({
top: '-85px'
});
} else if(jQuery('h1#logo').position().top != 0) {
jQuery('h1#logo').clearQueue();
jQuery('h1#logo').animate({
top: '0px'
});
}
});
</script>
精彩评论