如何查看滚动条的状态是否在顶部或底部? [英] How to check the scroll bar status is already at top or at end?
本文介绍了如何查看滚动条的状态是否在顶部或底部?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当用户设置"overflow:auto;"时显示滚动条.用户可以从上到下滚动内容.问题是,当滚动条位于底部还是顶部时,如何检查javascript/jquery?这样
The scroll bar is shown when user set "overflow:auto;" and the user can scroll things from top to bottom. The problem is , how can the javascript/jquery check when the scroll bar is either at the bottom or at the top? So that
if (is_scrollbar_top || is_scrollbar_end)
//do some thing..
那么有什么功能/方法可以检查这种状态?谢谢
So are there any funciton/ way to check such status? Thanks
更新:不起作用-使用jquery ui对话框
Updated: Not working- using jquery ui dialog
html:
<div class = "dialog" id="dialog" title="Past Issues"></div>
javascript:
$('#pastIssues').click(function (event) {
var issueString = 'product=Headline&year=2012&month=12';
$('.issues,#issuesBox').remove();
var dWidth = $(window).width() * 0.9;
var dHeight = $(window).height() * 0.9;
$( "#dialog" ).dialog({
height: dHeight,
width: dWidth,
modal: true,
draggable: false,
resizable: false,
});
get_past_issues(issueString,2012,12,event.type);
return false;
});
推荐答案
HTML:
<div id="mydiv" style="overflow: auto; height: 500px"></div>
脚本:
$(document).ready(function()
{
$("#mydiv").scroll(function()
{
var div = $(this);
if (div[0].scrollHeight - div.scrollTop() == div.height())
{
alert("Reached the bottom!");
}
else if(div.scrollTop() == 0)
{
alert("Reached the top!");
}
});
});
这篇关于如何查看滚动条的状态是否在顶部或底部?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文