开发者

POsition of image not changing with window scroll

开发者 https://www.devze.com 2022-12-29 13:55 出处:网络
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\");

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});
    });
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号