使用窗口滚动不改变图像的位置

我正在使用此代码在窗口被向下扫描时向下滑动图像,但没有任何事情发生

$('#left_img').css("top",$(window).scrollTop()+"px"); #left_img { margin:0 0 0 -55px !important; position:absolute; top:5px !important; } 

是否有可能找出整个滚动窗口的高度,然后如果图像达到一定高度,那么它应该停止向下滑动

您需要先实际捕获事件。

 $(window).scroll(function() { $('#left_img').css("top", $(window).scrollTop()+"px"); }); 

我对滚动和定位知之甚少,但如果你没有捕捉到这个事件,那可能就是你的问题。

我认为你的javascript没有意义! 为什么要滚动图像(使用javascript / jquery)?

你需要的只是设置

 #imageID { position: fixed; left: 20px; top: 20px; } 

它将滚动页面。 那么用脚本滚动图像的原因是什么?

让它有点整洁;

 $(window).scroll(function(){ var getbodyt = $(window).scrollTop(); var getbodyl = $(window).scrollLeft(); $("#left_img").css({top: getbodyt, left: getbodyl}); });