如何检测浏览器窗口中滚动的像素数?我需要这个来动态调整高度为100%的div的高度。
我使用的是jQuery。
编辑:我不能只使用scrollTop(),因为我使用的是100%高度的div,overflow设置为auto。由于这个原因,Firefox没有检测到浏览器滚动,唯一的滚动是100%x100%div...
发布于 2010-01-08 01:40:32
好吧,伙计们,我找到了:
$("div#container").scroll(function() {
var screenheight = parseInt($(document).height());
var scrolledpx = parseInt($("div#container").scrollTop());
var sum = screenheight+scrolledpx;
console.log($("div#container").scrollTop());
console.log("screen: " + screenheight);
console.log("sum=" + sum);
$("div.content").height(sum);
})发布于 2010-01-07 23:53:45
使用$(document).scrollTop():
$(document).scroll(function() {
console.log($(document).scrollTop());
})发布于 2015-07-17 19:33:30
您可以使用scrollTop()来查看您所访问的页面的深度。
$(window).scroll(function() {
console.log($(window).scrollTop());
if ($(window).scrollTop() > 200) {
$('#div').stop().animate({
'marginTop': $(window).scrollTop() + 'px',
'marginLeft': $(window).scrollLeft() + 'px'
}, 'slow');
}
});https://stackoverflow.com/questions/2021440
复制相似问题