Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-01-2012, 07:58 PM   PM User | #1
gerble1000
New Coder

 
Join Date: Nov 2011
Posts: 94
Thanks: 4
Thanked 0 Times in 0 Posts
gerble1000 is an unknown quantity at this point
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

}
gerble1000 is offline   Reply With Quote
Old 07-01-2012, 08:00 PM   PM User | #2
gerble1000
New Coder

 
Join Date: Nov 2011
Posts: 94
Thanks: 4
Thanked 0 Times in 0 Posts
gerble1000 is an unknown quantity at this point
the problem is the if statement but i think im doing all of this wrong anyway
gerble1000 is offline   Reply With Quote
Old 07-01-2012, 08:20 PM   PM User | #3
gerble1000
New Coder

 
Join Date: Nov 2011
Posts: 94
Thanks: 4
Thanked 0 Times in 0 Posts
gerble1000 is an unknown quantity at this point
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>
gerble1000 is offline   Reply With Quote
Old 07-01-2012, 08:57 PM   PM User | #4
gerble1000
New Coder

 
Join Date: Nov 2011
Posts: 94
Thanks: 4
Thanked 0 Times in 0 Posts
gerble1000 is an unknown quantity at this point
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 is offline   Reply With Quote
Old 07-02-2012, 11:50 AM   PM User | #5
gerble1000
New Coder

 
Join Date: Nov 2011
Posts: 94
Thanks: 4
Thanked 0 Times in 0 Posts
gerble1000 is an unknown quantity at this point
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>
gerble1000 is offline   Reply With Quote
Old 07-02-2012, 12:45 PM   PM User | #6
vwphillips
Senior Coder

 
Join Date: Mar 2005
Location: Portsmouth UK
Posts: 4,380
Thanks: 3
Thanked 466 Times in 453 Posts
vwphillips is a jewel in the roughvwphillips is a jewel in the roughvwphillips is a jewel in the rough
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>
__________________
Vic

God Loves You and will never love you less.

http://www.vicsjavascripts.org.uk/

If my post has been useful please donate to http://www.operationsmile.org.uk/
vwphillips is offline   Reply With Quote
Users who have thanked vwphillips for this post:
gerble1000 (07-02-2012)
Old 07-02-2012, 01:15 PM   PM User | #7
gerble1000
New Coder

 
Join Date: Nov 2011
Posts: 94
Thanks: 4
Thanked 0 Times in 0 Posts
gerble1000 is an unknown quantity at this point
brilliant thank you again
gerble1000 is offline   Reply With Quote
Old 07-02-2012, 09:53 PM   PM User | #8
gerble1000
New Coder

 
Join Date: Nov 2011
Posts: 94
Thanks: 4
Thanked 0 Times in 0 Posts
gerble1000 is an unknown quantity at this point
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
gerble1000 is offline   Reply With Quote
Old 07-03-2012, 09:43 AM   PM User | #9
vwphillips
Senior Coder

 
Join Date: Mar 2005
Location: Portsmouth UK
Posts: 4,380
Thanks: 3
Thanked 466 Times in 453 Posts
vwphillips is a jewel in the roughvwphillips is a jewel in the roughvwphillips is a jewel in the rough
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>
__________________
Vic

God Loves You and will never love you less.

http://www.vicsjavascripts.org.uk/

If my post has been useful please donate to http://www.operationsmile.org.uk/
vwphillips is offline   Reply With Quote
Users who have thanked vwphillips for this post:
gerble1000 (07-03-2012)
Old 07-03-2012, 04:17 PM   PM User | #10
gerble1000
New Coder

 
Join Date: Nov 2011
Posts: 94
Thanks: 4
Thanked 0 Times in 0 Posts
gerble1000 is an unknown quantity at this point
that is perfect
nice and smooth
gerble1000 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:25 AM.


Advertisement
Log in to turn off these ads.