检测距离顶部jQuery滚动的距离 [英] detect distance scrolled from top jquery
本文介绍了检测距离顶部jQuery滚动的距离的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何检测浏览器窗口中滚动的像素数? 我需要它来动态调整100%高度div的高度...
How can I detect the number of pixels scrolled in a browser window? I need this to dynamically adjust the height of a 100% height div...
我正在使用jQuery.
I'm using jQuery.
我不能只使用scrollTop(),因为我正在将100%高度的div设置为自动溢出. Firefox因此无法检测到浏览器滚动,唯一的滚动是100%x100%div ...
I cannot just use scrollTop() because I'm working with a 100% height div with overflow set to auto. Firefox does not detect browser scrolling due to this, the only thing scrolling is a 100%x100% div...
推荐答案
好的,我发现了:
$("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);
})
这篇关于检测距离顶部jQuery滚动的距离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文