...

View Full Version : this would be cool if i could get it working



gerble1000
07-01-2012, 08:58 PM
it scrolls smoothly to position but i need it to stop once it gets there.
whats wrong with this code

function pageScroll() {
if (document.body.scrollTop = '530'){ clearTimeout(scrolldelay); return;}

window.scrollBy(0,5); // horizontal and vertical scroll increments
scrolldelay = setTimeout('pageScroll()',15); // scrolls every 100 milliseconds

}

gerble1000
07-01-2012, 09:00 PM
the problem is the if statement but i think im doing all of this wrong anyway

gerble1000
07-01-2012, 09:20 PM
yay i done it with a simple for loop.
i feel silly now

<script type="text/javascript">
function pageScroll() {
for (i=1; i<530; i++){
window.scrollBy(0,1);
}

}
</script>

gerble1000
07-01-2012, 09:57 PM
works great on i.e and firefox but on my server there is no graphics accelirator so it takes about 30 seconds to reach the desire scroll height.
is there a wau to check if there is an accelirator card and do an if statement on that

gerble1000
07-02-2012, 12:50 PM
i was wrong this does not work in firefox
this just skips right down to the correct position but not smooth at all. when in ie it works lovely. could somebody give me a pointer please


<script type="text/javascript">
function pageScroll()
{
var speed2 =1;
for (i=0; i<531; i++)
{
var speed= 1;

if (a=10 && i<200){speed++;speed2=0;}
if (a=10 && i>201){speed--;speed2=0;}
if (speed<1){speed++;}
if (document.body.scrollTop >530){i=531;}

window.scrollBy(0,speed);
speed2++;
}

}
</script>

vwphillips
07-02-2012, 01:45 PM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<title></title>
</head>

<body>
<input type="button" name="" value="ScrollTo 530" onmouseup="ScrollTo(530,1000);"/>
<div style="height:2000px;" ></div>
<script> vic=0; </script>
<form name=Show id=Show style="position:absolute;visibility:visible;top:700px;left:0px;" >
<input size=100 name=Show0 >
</form>
<script type="text/javascript">
/*<![CDATA[*/

function ScrollTo(to,ms) {
var f=window.innerHeight?window.pageYOffset:document.documentElement.clientHeight?document.documentEleme nt.scrollTop:document.body.scrollTop;
clearTimeout(ScrollTo.dly);
animate(f,to,new Date(),ms);
}

function animate(f,t,srt,mS){
var ms=new Date().getTime()-srt,now=(t-f)/mS*ms+f;
if (isFinite(now)){
window.scrollTo(0,now);
}
if (ms<mS){
ScrollTo.dly=setTimeout(function(){ animate(f,t,srt,mS); },10);
}
else {
window.scrollTo(0,t);
}
}



/*]]>*/
</script>
</body>

</html>

gerble1000
07-02-2012, 02:15 PM
brilliant thank you:thumbsup: again

gerble1000
07-02-2012, 10:53 PM
i got the feeling that your code is supposed to slow down when it gets close to the target. but it keeps the same consistent speed. is there a way to make it act like an elivator stopping :)

vwphillips
07-03-2012, 10:43 AM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<title></title>
</head>

<body>
<input type="button" name="" value="ScrollTo 530" onmouseup="ScrollTo(530,1000);"/>
<div style="height:2000px;" ></div>
<script> vic=0; </script>
<form name=Show id=Show style="position:absolute;visibility:visible;top:700px;left:0px;" >
<input size=100 name=Show0 >
</form>
<script type="text/javascript">
/*<![CDATA[*/

function ScrollTo(to,ms) {
var f=window.innerHeight?window.pageYOffset:document.documentElement.clientHeight?document.documentEleme nt.scrollTop:document.body.scrollTop;
clearTimeout(ScrollTo.dly);
animate(f,to,new Date(),ms,Math.PI/(2*ms));
}

function animate(f,t,srt,mS,i){
var ms=new Date().getTime()-srt,now=(t-f)*Math.sin(i*ms)+f;
if (isFinite(now)){
window.scrollTo(0,now);
}
if (ms<mS){
ScrollTo.dly=setTimeout(function(){ animate(f,t,srt,mS,i); },10);
}
else {
window.scrollTo(0,t);
}
}





/*]]>*/
</script>
</body>

</html>

gerble1000
07-03-2012, 05:17 PM
that is perfect :thumbsup:
nice and smooth



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum