如何检测浏览器窗口中滚动的像素数?我需要这个动态调整100%高度div的高度...
我正在使用jQuery.
编辑:我不能只使用scrollTop(),因为我正在使用100%高度div,溢出设置为auto.由于这个原因,Firefox没有检测到浏览器滚动,唯一滚动的是100%x100%div ...
Dav*_*ing 77
用途$(document).scrollTop():
$(document).scroll(function() {
console.log($(document).scrollTop());
})
Run Code Online (Sandbox Code Playgroud)
好吧,伙计们,我找到了:
$("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);
})
Run Code Online (Sandbox Code Playgroud)
您可以使用scrollTop()来查明您浏览的页面有多远。
$(window).scroll(function() {
console.log($(window).scrollTop());
if ($(window).scrollTop() > 200) {
$('#div').stop().animate({
'marginTop': $(window).scrollTop() + 'px',
'marginLeft': $(window).scrollLeft() + 'px'
}, 'slow');
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
68800 次 |
| 最近记录: |