use*_*842 6 javascript jquery scroll
有很多网站(如www.9gag.com)检查你的滚动百分比,并确定你是否80%下降.如果是这样,它会显示更多内容.
我想看到的代码示例:
$(window).scroll(function () {
if(scroll.height >= 80%) {
// the scroll is about 80% down.
}
});
Run Code Online (Sandbox Code Playgroud)
我想知道如何检查滚动是否大约80%,像那些网站?
小智 7
您检查页面的高度,并将此值与当前位置进行比较.如果当前位置是高度的80%而不是运行某些代码.
$(window).scroll(function ()
{
var content_height = $(document).height();
var content_scroll_pos = $(window).scrollTop();
var percentage_value = content_scroll_pos * 100 / content_height;
if(percentage_value >= 80)
{
console.dir("the scroll is about 80% down.");
}
});
Run Code Online (Sandbox Code Playgroud)
没有测试它,但应该做你想要的:)
感谢Alvaro将我的代码添加到小提琴中:http://jsfiddle.net/2wSSS/7/
| 归档时间: |
|
| 查看次数: |
2893 次 |
| 最近记录: |