View Full Version : scroller help

02-03-2006, 07:42 PM
i need some help

i need a java scripts that scrolls the page when i click on a link

something similar

but not an "auto scroller" only if a click on an url

plz help

ps. sry for bad english

02-03-2006, 09:22 PM
<a href="#" onclick="window.scrollTo(0, 250);return false">Link Text</a>

The 250 is the number of pixels from the top the window that its scroll state will become. A nice touch is to add an anchor on your page where you want to scroll to:

<a name="sp1"></a>

and make the link like so:

<a href="#sp1" onclick="window.scrollTo(0, 250);return false">Link Text</a>

That way, even non-javascript enabled browsers will get there. In fact, you could just use:

<a href="#sp1">Link Text</a>

Unless you really need the javascript part for some reason.

02-04-2006, 02:39 PM
yeah, but i want to have the effect, i want to see how its scrolling, u know what i mean? not to move the page on x cordinate, to have the scrolling effect

02-04-2006, 03:06 PM
i found it!!

3 parts to this script
part 1

<SCRIPT Language="JavaScript">
This header must remain in place
Copyright 1999 All Rights Reserved.
Author: Martin Kretzmann
License: GNU General Public License
/* Configuration */

// number of pixels to scroll down...
n = 700


function scrolldown(){
for (I=1; I<=n; I++){

function scrollup(){
for (I=n; I>=1; I--){
part 2 - this is the scroll up button
<!-- --><form>
<input type=button value="ScrollDown" onClick="scrolldown()">
</form><!--A1 -->
part 3 - this is the scroll down button
<!-- --><form>
<input type=button value="ScrollUp" onClick="scrollup()">
</form><!--A1 -->

thx anyway for help :D

02-04-2006, 03:09 PM
<script type="text/javascript">
function scroll(pos) {
window.scrollPosition = function() {
if(typeof window.document.body.scrollTop != "undefined") return window.document.body.scrollTop;
else if(typeof window.pageYOffset != "undefined" return window.pageYOffset;
else return -20;
if(window.pageYOffset >= pos || window.scrollPosition == -20) return;
window.scrollTo(0, window.scrollPosition() + 20);
window.setTimeout("scroll(" + pos + ")", 100);
<a href="#anchor" onclick="scroll(600);">Scroll</a>Adjust the numbers in green to suit taste.

/EDIT: Heh, beaten to it.