Enjoy an ad free experience by logging in. Not a member yet?
Register .
07-01-2012, 07:58 PM
PM User |
#1
New Coder
Join Date: Nov 2011
Posts: 94
Thanks: 4
Thanked 0 Times in 0 Posts
this would be cool if i could get it working
it scrolls smoothly to position but i need it to stop once it gets there.
whats wrong with this code
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
}
07-01-2012, 08:00 PM
PM User |
#2
New Coder
Join Date: Nov 2011
Posts: 94
Thanks: 4
Thanked 0 Times in 0 Posts
the problem is the if statement but i think im doing all of this wrong anyway
07-01-2012, 08:20 PM
PM User |
#3
New Coder
Join Date: Nov 2011
Posts: 94
Thanks: 4
Thanked 0 Times in 0 Posts
yay i done it with a simple for loop.
i feel silly now
Code:
<script type="text/javascript">
function pageScroll() {
for (i=1; i<530; i++){
window.scrollBy(0,1);
}
}
</script>
07-01-2012, 08:57 PM
PM User |
#4
New Coder
Join Date: Nov 2011
Posts: 94
Thanks: 4
Thanked 0 Times in 0 Posts
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
07-02-2012, 11:50 AM
PM User |
#5
New Coder
Join Date: Nov 2011
Posts: 94
Thanks: 4
Thanked 0 Times in 0 Posts
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
Code:
<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>
07-02-2012, 12:45 PM
PM User |
#6
Senior Coder
Join Date: Mar 2005
Location: Portsmouth UK
Posts: 4,380
Thanks: 3
Thanked 466 Times in 453 Posts
Code:
<!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.documentElement.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>
Users who have thanked vwphillips for this post:
07-02-2012, 01:15 PM
PM User |
#7
New Coder
Join Date: Nov 2011
Posts: 94
Thanks: 4
Thanked 0 Times in 0 Posts
brilliant thank you
again
07-02-2012, 09:53 PM
PM User |
#8
New Coder
Join Date: Nov 2011
Posts: 94
Thanks: 4
Thanked 0 Times in 0 Posts
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
07-03-2012, 09:43 AM
PM User |
#9
Senior Coder
Join Date: Mar 2005
Location: Portsmouth UK
Posts: 4,380
Thanks: 3
Thanked 466 Times in 453 Posts
Code:
<!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.documentElement.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>
Users who have thanked vwphillips for this post:
07-03-2012, 04:17 PM
PM User |
#10
New Coder
Join Date: Nov 2011
Posts: 94
Thanks: 4
Thanked 0 Times in 0 Posts
that is perfect
nice and smooth
Jump To Top of Thread
Thread Tools
Rate This Thread
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
All times are GMT +1. The time now is 10:25 AM .
Advertisement
Log in to turn off these ads.