I am using this code to slide the image down when window is scroled down but nothing is happenning
$('#left_img').css("top",$(window).scrollTop()+"px");
#left_img {
margin:0 0 0 -55px !important;
position:absolute;
top:5px !important;
}
Is it possible to find out how much is height of whole 开发者_JAVA百科scroll window and then if image reaches certain height then it should stop sliding down
You need to actually capture the event first.
$(window).scroll(function() {
$('#left_img').css("top", $(window).scrollTop()+"px");
});
I don't know much about scrolling and positioning, but if you're not capturing the event, that could be you're problem.
I think your javascript doesn't make sense! Why Do you scrolling Image (with javascript/jquery)?
All you need is to set
#imageID
{
position: fixed;
left: 20px;
top: 20px;
}
It will scroll with page. So whats the reason to scrollimage with script?
Make it a little bit neater;
$(window).scroll(function(){
var getbodyt = $(window).scrollTop();
var getbodyl = $(window).scrollLeft();
$("#left_img").css({top: getbodyt, left: getbodyl});
});
精彩评论