![]()
It has been a while since I presented some unobtrusive (hopefully useful) JavaScript function. Recently I have been working on a project that demanded content scrolling, so instead of reaching out for some heavy unobtrusive solutions, I decided to write my own function. As I was developing it I kept simplifying it so I came down to what I am presenting today - Easy Scroll v1.0, an accessible, unobtrusive content scroller.
I am not using any JS libraries with Easy Scroll. Although I enjoy jQuery a lot, I believe that it is important to code in "regular" JS, just not to forget it :)
So, Easy Scroll is standalone, lightweight script that is very easily applicable.
Take a look at the demo | Download Easy Scroll v1.0
Features
Easy Scroll is capable of scrolling any type of content by using unobtrusive JavaScript. It has up and down scroll options and reset button that places your content in the default position.
It also features double speed. When buttons are rolled over, slow scrolling starts. When buttons are pressed, speed increases.
Ok, let's get it going
To start with Easy Scroll download the script, and link it to your document by placing this line of code inside the head tag:
<script type="text/javascript" src="easyscroll/easyscroll.js"></script>
You'll also need a div with custom id (default is "myContent"). Then you should put some content in it of course :)
<div id="myContent"> <!-- YOUR CONTENT HERE --> </div>
Believe it or not, as far as the markup is concerned, that's it!
The script takes it over from here.
It creates another div id="easyscroll" and places your content div inside and takes care of the absolute positioning, scroll buttons and scrolling.
Setting things up
You might want to set the variables in the JavaScript. When you open easyscroll.js you'll notice these variables in config area
var id = "myContent";
This id matches the one you have in your html file for content div. If you wish to change it, you must do it in both html and JavaScript
var nav = ["Scroll Up", "Scroll Down", "Reset"];
Text that appears inside of each scroll button.
var navId = ["btnUp", "btnDown", "btnReset"];
These are optional id's for scroll buttons in case you want to apply some specific CSS for each.
var speed = 5;
Movement speed. The larger the number the faster the scrolling will be.
var height = 200;
Desired height of the Easy Scroll area.
Use css to style the content area. Oh yes, buttons are rendered as unordered list. Use css to style those too :)
ani625 3 Apr, 2008
And btw, Link updated on delicious.
cssglobe 3 Apr, 2008
b0li 3 Apr, 2008
greetings
kerberoS 3 Apr, 2008
WebTecker 3 Apr, 2008
cssglobe 3 Apr, 2008
Tomas M 3 Apr, 2008
can be used for left/top scrolling ?
cssglobe 3 Apr, 2008
Germán 3 Apr, 2008
davidwalsh 4 Apr, 2008
Steph 4 Apr, 2008
Thanks Alen!
Chad Smith 4 Apr, 2008
Derek 4 Apr, 2008
cssglobe 4 Apr, 2008
ani625 4 Apr, 2008
cssglobe 4 Apr, 2008
Roman Lokhov 5 Apr, 2008
But don't you think that to use offsetHeight and offsetTop is very slow? Especially if the "myContent" have many content (images, flash)?
webfruits 6 Apr, 2008
cssglobe 6 Apr, 2008
Philly Dude 9 Apr, 2008
emre 11 Apr, 2008
how can I replace "graphic" instead of texts...
I mean; I want add UP and DOWN ARROW to the leftside of my div...
can I do that with this script?
cssglobe 11 Apr, 2008
Alberto 13 Apr, 2008
Thanks, great job.
AndreiZorrov 13 Apr, 2008
I searched for a very long time
mexx63 17 Apr, 2008
Thanks
cssglobe 17 Apr, 2008
Mya 17 Apr, 2008
Deborah 22 Apr, 2008
dj
Juvenn 22 Apr, 2008
Krystal 23 Apr, 2008
Daddo 29 Apr, 2008
I think I'll be using it soon on my sites...
:-D
Aaron Mc Adam 6 May, 2008
graham 7 May, 2008
However, I'm wondering how to add two blocks of scrolling text at different points on a page. If it uses ids, is this even possible?
weremoose 10 May, 2008
Pete 13 May, 2008
Jim 15 May, 2008
victoria 23 May, 2008
I am a beginner too...can't figure out what webfruits did.
victoria 29 May, 2008
Here is the page I'm using it on http://www.pslarchitects.com/projects.html
fracto 29 May, 2008
Thank you very much!! Good job!
Tim Wye 5 Jun, 2008
Jacob 6 Jun, 2008
But, Is it possible to make it scroll horizontally instead?
- Jacob
Matias 11 Jun, 2008
Rainer 2 Jul, 2008
Simon Dempsey 5 Jul, 2008
I notice a number ppl struggling witht the hover over image function (as per Webfruits site) - this is done with css people - check out this code from my style sheet:
#btnUp{
background-image: url(../images/global/scroll-up_off.gif);
background-repeat: no-repeat;
float: left;
height: 9px;
width: 67px;
margin-right: 4px;
}
#btnUp.over {
background-image: url(../images/global/scroll-up_on.gif);
background-repeat: no-repeat;
text-decoration:none;
}
#btnDown{
background-image: url(../images/global/scroll-down_off.gif);
background-repeat: no-repeat;
float: left;
height: 9px;
width: 67px;
margin-right: 4px;
}
#btnDown.over {
background-image: url(../images/global/scroll-down_on.gif);
background-repeat: no-repeat;
text-decoration:none;
}
Great job again Alen!
nodosur 6 Jul, 2008
Chrissy 9 Jul, 2008
Gabor 10 Jul, 2008
If you want to use image buttons instead of text buttons do the following:
1. Change script var nav to: var nav = ["", "", ""];
2. Take out the line: background in style in #easyscrollnav li
3. Add this lines to style:
#btnUp{
background:url(your_image.jpg)no-repeat 0 0;
}
#btnDown{
background:url(your_image.jpg)no-repeat 0 0;
}
Dempo 11 Jul, 2008
Saboravallarta 11 Jul, 2008
dario 15 Jul, 2008
But if i'd like insert more than one?
Is it possible?
Michael 18 Jul, 2008
If you'll notice in the html, the div for the scrolling content is labeled as an ID, not a CLASS, ergo, one per page.
Which is not to say that some tweak to the js might allow for multilple IDs of different names. I'm not sure of the liklihood or not, just a thought. Perhaps the author might chime in.
Oh, and thanks for a very nice implementation.
Owain 1 Aug, 2008
Im trying to use easyscroll in the same way as the webfruits site. where the buttons are down the right side of the content area...
The site im currently working on has a scroll bar by using the overflow css property.. Does anyone know anywhere online which shows you how to position the buttons to the right?
Jorgen Farum Jensen 1 Aug, 2008
container.style.padding = "1em"
This doesn't seem to work. I'm sure there must be a way, but how?
Steph 3 Aug, 2008
Still wish I could switch the buttons though - but still good scroller!
JanB 8 Aug, 2008
Be allows prepared for users like me ;)
sjl 11 Aug, 2008
Pundit 12 Aug, 2008
Maybe I'm misunderstanding the intent here - do you have a use case which demonstrates the need?
Cheers.
vicky 19 Aug, 2008
I noticed that this website is using easy scroller but v2. The site URL is http://www.ski.com. I like the way I can scroll with arrows and how it auto scrolls. Is this the same base script as what you are refering to or is this another? I can't find information on how to mock it up.
Thanks
vicky
Spencer Smith 19 Aug, 2008
spencer
Shobz 24 Aug, 2008
This Script REALLY rocks!!... I just love it!!! Thnks a ton! :)
Jonas 25 Aug, 2008
in the js-file, change this line:
parent.insertBefore(ul,container);
to:
parent.insertAfter(ul,container);
Jonas 25 Aug, 2008
var parent = referenceElement.parentNode;
var nextSibling = referenceElement.nextSibling;
if ( nextSibling) {
parent.insertBefore(newElement, nextSibling);
} else {
parent.appendChild(newElement);
}
}
Jonas 25 Aug, 2008
Spencer Smith 26 Aug, 2008
thanks for the tip. For some reason though, i can't get it to work. The buttons just disappear.
you can look at my stuff here (i posted an example):
http://avantstudios.com/clients/waldonstudio/web0808/portfolio-test99.html
http://avantstudios.com/clients/waldonstudio/web0808/easyscroll.js
http://avantstudios.com/clients/waldonstudio/web0808/waldon4.css
Thanks.
spencer
melania 27 Aug, 2008
i've been looking for something like this.
very useful and nicely clear !! >;)
Ted 10 Sep, 2008
This is a great scroller and an excellent basis for any project you wish to build on.
However, I hava a little problem. The scroller works fine using IE6 but I am having a problem with scrolling when using Firefox.
Firefox:
1) Mouse hover over the down button, scrolling functions a little jumpy.
2) Mouse over the up button, no scrolling on hover. Scrolls at half speed when button clicked.
Has anybody experienced this problem and if so, maybe you can advise the fix. Again, using IE the scroller functions as designed
Thanks
Kristof 15 Nov, 2008
Great scroller but I doesn't work for me on IE7. It will only display single words per line. On IE6 & Firefox it works ok. Did anyone else had same problem? Any ideas?
Thank you for any assistance :)
Kristof
tenksheep 23 Nov, 2008
Abhinav Shine 25 Nov, 2008
Stephen 9 Dec, 2008
mayavada 15 Jan, 2009
I follow the instructions by putting the Javascript link in the Head of my HTML document and I create and assign a div id "myContent". I even took the CSS off the demo and placed it in along with everything else.
Is there something I'm missing? Do I have to format any overflow, height or width in myContent CSS?
Thanks All.
Donna 16 Jan, 2009
Thanks again, much appreciated!
Donna
Donna 16 Jan, 2009
Thanks for such a nifty tool! :)
Ronald 3 Feb, 2009
Jerome 5 Feb, 2009
Einar Pall Svavarsson 9 Feb, 2009
I have used this with good result and small changes on two websites.The first one with one scrollbar and the second with two scrollbars.
http://www.sigtryggurbjarni.is/nav02.html - one scrollbar
and on the University of Iceland web page
http://www.hi.is/is/felagsvisindasvid_deildir/felags_og_mannvisindadeild/adal/forsida - two scrollbars.
Sorry about the long url.
Best regards
Einar
jackie fitts 18 Feb, 2009
thank you
Einar Pall Svavarsson 19 Feb, 2009
For those who are looking for 2 on the same page, please read my comment above from February 9th.
Webtiful Search Engine SEO 26 Feb, 2009
fatherb 3 Mar, 2009
woody 25 Mar, 2009
Otherwise fantastic script - thank you.
Matt.
ana 31 Mar, 2009
Thanks a lot for sharing
http://sulvision.com
xaer8 4 May, 2009
Cliff 12 May, 2009
Best regards,
Cliff
JonDee 15 Jun, 2009
I am having a problem, though and was hoping someone cold help. If I put the div in a table, like
this: <td rowspan="2" valign="top"><div id="myContent">
My text is very narrow in IE7. Is there a way to fix this?
Thanks!!!!
Mic 19 Jun, 2009
Jeevan4u 20 Jun, 2009