我正在使用 2d 滚动视图中的 webview,所以每当我尝试获取 computescrollrange()、computescrolloffset() 等时,这些方法都不会返回任何值,所以我想使用 javascript 来检测到达的水平滚动条webview的结尾所以请建议我如何创建函数,该函数将返回布尔值来判断它是否结束,或者在android或javascript/jquery中使用任何方式
问问题
1487 次
2 回答
0
<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>Scroll Detect</title>
<script type="text/javascript">
var sym=0;
var sxm=0;
var cxs=0;
var cys=0;
window.onscroll=function (){
if ('scrollMaxX' in window){
sxm=window.scrollMaxX;
sym=window.scrollMaxY;
}
else{
sxm = document.documentElement.scrollWidth - document.documentElement.clientWidth;
sym = document.documentElement.scrollHeight - document.documentElement.clientHeight;
}
if ('pageXOffset' in window) {// all browsers, except IE before version 9
cxs=window.pageXOffset;
cys=window.pageYOffset;
}
else { // Internet Explorer before version 9
cxs=document.documentElement.scrollLeft;
cys=document.documentElement.scrollTop;
}
if(cys==sym&&sym>0){alert("The horizontal scroller in the bottom")}
if(cxs==sxm&&sxm>0){alert("The horizontal scroller in the right")}
}
</script>
</head>
<body>
<div style="height:4000px; background:#909090; width:900px"></div>
</body>
</html>
您可以通过您的功能替换警报或使用布尔值来减少烦人
<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>Scroll Detect</title>
<script type="text/javascript">
var sym=0;
var sxm=0;
var cxs=0;
var cys=0;
var xst=false;//is horizontal scroller on top
var xsb=false;//is horizontal scroller on bottom
var ysl=false;//is vertical scroller on left
var ysr=false;//is vertical scroller on right
window.onscroll=function (){
if ('scrollMaxX' in window){// all browsers, except IE lower than 9
sxm=window.scrollMaxX;
sym=window.scrollMaxY;
}
else{ // Internet Explorer lower than 9
sxm = document.documentElement.scrollWidth - document.documentElement.clientWidth;
sym = document.documentElement.scrollHeight - document.documentElement.clientHeight;
}
if ('pageXOffset' in window) {// all browsers, except IE lower than 9
cxs=window.pageXOffset;
cys=window.pageYOffset;
}
else { // Internet Explorer lower than 9
cxs=document.documentElement.scrollLeft;
cys=document.documentElement.scrollTop;
}
if(cys==sym&&sym>0){xsb=true;xst=false;}
if(cxs==sxm&&sxm>0){ysr=true;ysl=false;}
if(cys==0&&sym>0){xsb=false;xst=true;}
if(cxs==0&&sxm>0){ysr=false;ysl=true;}
}
</script>
</head>
<body>
<div style="height:4000px; background:#909090; width:900px"></div>
</body>
</html>
于 2013-05-06T13:53:01.943 回答
0
<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>Scroll Detect</title>
<script type="text/javascript">
var cxs=0;
var cys=0;
window.onscroll=function (){
if ('scrollMaxX' in window){
sym=window.scrollMaxY;
}
else{
sym = document.documentElement.scrollHeight - document.documentElement.clientHeight;
}
if ('pageXOffset' in window) {// all browsers, except IE before version 9
cys=window.pageYOffset;
}
else { // Internet Explorer before version 9
cys=document.documentElement.scrollTop;
}
if(cys==sym&&sym>0){alert("The horizontal scroller in the bottom")}
}
</script>
</head>
<body>
于 2013-05-08T18:46:26.353 回答