-2

i am working with a webview that is inside 2d scroll view so whenever i tried to get computescrollrange() ,computescrolloffset() etc so these methods are not returning any value so i want to use the javascript to detect that horizontal scroll bar reached at the end of webview so please suggest me the way how to create the function that will return the Boolean value to tell whether it is at end or not using any way either in android or javascript/jquery

royhowie
  • 11,075
  • 14
  • 50
  • 67
Ravi
  • 2,277
  • 3
  • 22
  • 37
  • 3
    Did you write this question on a mobile phone? I little more formatting, and proper punctuation would be nice. – Šime Vidas May 06 '13 at 11:20

2 Answers2

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>

you can repleace alert by by your function or use this less annoying with Boolean

<!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>
Karim Lee
  • 41
  • 1
  • 4
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>
Karim Lee
  • 41
  • 1
  • 4