Jul 25, 2008

Javascript Scroll Bar - A scroll bar for your webpage using javascript

Free Web Hosting, No Ads > CONTRIBUTE > Tutorials
Pages: 1, 2

free web hosting

Javascript Scroll Bar - A scroll bar for your webpage using javascript

t3jem
In this tutorial I will show you how to create two buttons in the bottom left of the screen that, when hovered over, will scroll the page.

Now to start with, we must create a our buttons, the first line will create a div element, or block. Using blocks you can position items anywhere on a page. We use the ID property just to let us know what the block is used for, as for the first block, its obvious that it contains the vertical buttons and the second two blocks contains the horizontal buttons.
The style property of the div tag tells the browser how to draw it, in the first block we set it to fixed, which keeps the block in one place on the window, then we follow it with coordinates, 10 pixels from the right and 10 pixels from the bottom.
Same goes with our seconds block except it is 60 pixels from the right.
Now we use anchor tags so we can use the mouseover feature, so when the mouse moves over each image the image can change our speed variable that scrolls our screen. We also use the mouseout property to stop the screen from scrolling when we leave the image.

Below is our first few lines of code.

CODE
<div id="verticalbuttons" style="position: fixed; right:10px; bottom:10px;">
  <a onmouseover="ycurrentscrollspeed=-staticscrollspeed" onmouseout="ycurrentscrollspeed=0"><img
  src="up_arrow.gif" border="0"></a>
  
  <a onmouseover="ycurrentscrollspeed=staticscrollspeed" onmouseout="ycurrentscrollspeed=0"><img
  src="down_arrow.gif" border="0"></a>
  </div>


Note: you can roposition the buttons by changing cooridinates. Below I will split the block into two instead of one for both buttons. The left button will be all the way on the left site of the screen on the bottom, while the right will be at the right side of the screen on the bottom. If you wanted to put the buttons at the top instead you could change "bottom:10px" to "top:10px" so it will be 10 pixels from the top or however many pixels you want it from the top/bottom or where ever.

CODE
<div id="leftbutton" style="position: fixed; right:60px; bottom:10px;">
  <a onmouseover="xcurrentscrollspeed=-staticscrollspeed" onmouseout="xcurrentscrollspeed=0"><img
  src="left_arrow.gif" border="0"></a>
</div>
<div id="rightbutton" style="position: fixed; left: 10px; bottom:10px">
  <a onmouseover="xcurrentscrollspeed=staticscrollspeed" onmouseout="xcurrentscrollspeed=0"><img
  src="right_arrow.gif" border="0"></a>
  </div>


Now we start our script and initialize our variables. The first variable is static and doesn't change, we use this to define how fast we want our page to scroll, you may change the speed if desired.
The other two variables are used to keep track of the current speed of scrolling on the x and y axiis, (x axis is left-right, y axis is up-down). We set these to zero because we don't want to be scrolling when the user loads the page.
CODE
<script>
  
  var staticscrollspeed=3 //Enter scroll speed in integer (Advised: 1-3)
  
  var xcurrentscrollspeed=0
  var ycurrentscrollspeed=0


our next function will do the actual scrolling. We scroll using the function "scrollBy". The first argument is the speed on the x axis to scroll and the second is the speed on the y axis. We, of course, fill these arguments with our speed variables for each axis.

Then last, but not least, we set an interval to call our scroll function every 20 milliseconds.

CODE
function scroll(){
    window.scrollBy(xcurrentscrollspeed,ycurrentscrollspeed)
  }
  
  setInterval("scroll()",20)
  
  </script>


I hope you enjoyed the tutorial and found it helpful!

if you have any questions/comments, feel free to private message me.

 

 

 


Reply

zak92
nice on you helped me you shall get youre creds soon.
Question: How can i make the position of the pics move? For example i want the up button to go on top and down on bottom and same with sideways.

Reply

t3jem
QUOTE(zak92 @ Apr 7 2007, 08:13 AM) *
Question: How can i make the position of the pics move? For example i want the up button to go on top and down on bottom and same with sideways.


Alright, I just edited the top part of the code. If you want to put the up button at the top of the screen you change the style from "position: fixed; right: 10px; bottom: 10px;" to "position: fixed; right: 10px; top: 10px;" so instead of being 10 pixels from the bottom it will be 10 pixels from the top. Also you can change the pixels to percents/other units and you can also change how much space there is from the edges of the screen, just remember "bottom" is space from the bottom, top is space from the top, left and right are space from the left and right respectively.

Glad you enjoyed my tutorial biggrin.gif

 

 

 


Reply

Unholy Prayer
That's a pretty good code, man. Nice work. I might use it.

Reply

zak92
Not exactly. I wanted to have the up arrow on the top and the bottom arrow completely out at the bottom. Help. Thanks

Reply

t3jem
ok, if you wanted to split the up and down arrows just do it just like the left/right arrows, here's the code for it.

CODE
<div id="topbutton" style="position: fixed; right:10px; top:10px;">
  <a onmouseover="ycurrentscrollspeed=-staticscrollspeed" onmouseout="ycurrentscrollspeed=0"><img
  src="up_arrow.gif" border="0"></a>
</div>
<div id="bottombutton" style="position: fixed; right: 10px; bottom:10px">
  <a onmouseover="ycurrentscrollspeed=staticscrollspeed" onmouseout="ycurrentscrollspeed=0"><img
  src="down_arrow.gif" border="0"></a>
  </div>


just splite the block, and change the position.

Reply

zak92
you know what man i reallly love you. Thanks a lot. I hope you got your creds by now!

Reply

anish
Thanks for sharing

Reply

zak92
Hey maybe since its time you should post like more advanced version maybe including a bar to keep track of where you are . Great job though.

Reply

viettre
this tut nice thanks for share

Reply

Latest Entries

hippiman
I don't think this works in IE, but I don't really care because I hate IE.

It works perfectly for me. That's pretty cool.

Reply

jsjs
hi there
if you want try somethig different try this javascript scrollbar
it works perfectly in all browsers and its easy to set up.
also support multy scrollbars on 1 page

Reply

rize619
good idear for frameset scroll bar
will it work there in frames ?

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Pages: 1, 2
Recent Queries:-
  1. javascript x-axis ,y-axis - 0.98 hr back. (1)
  2. pretty javascript scroll - 1.41 hr back. (1)
  3. scrollbar sidebar onmouseover - 4.35 hr back. (1)
  4. change style of a scroll bar, css - 65.34 hr back. (1)
  5. mootools scollbar - 75.16 hr back. (1)
  6. scroll javascript bar - 84.06 hr back. (1)
  7. change loading items in bottom scrollbar - 118.76 hr back. (1)
  8. javascript scrollbar - 43.61 hr back. (3)
  9. javascript scrollbar coordinates - 137.01 hr back. (1)
  10. javascript scroll bar code - 166.25 hr back. (1)
  11. javascript scrollbar button - 166.34 hr back. (1)
Similar Topics

Keywords : javascript, scroll, bar, scroll, bar, webpage, javascript

  1. Lesser Known Useful Javascript Features
    (2)
  2. Make A Moderately-secure Password System Using Javascript
    using file redirection to hide the password. (4)
    JavaScript is very handy at making forms, allowing for much more customization and easier ways to
    send data. So making Login forms using JavaScript may seem to many to be a very feasable idea.
    However, JavaScript is very bad at protecting Passwords, as since the passwords are not encypted and
    the whole JavaScript code is in the page, a person could just view the Page Source and find out
    everything. Even if you use an external JavaScript, it would still be poor as the file name for the
    external JavaScript would still be revealed. But I have an answer! There is a rela....
  3. Simple Javascript And Password System
    How to protect your pages with password (6)
    The quickest way to get a password protection system up and running is to use a Prompt box in
    JavaScript that has a title like "Enter your Email Address". Only you and the relevant users know
    what the password should be, could even be one each, that can be sorted out at the next page then
    pass the "input" directly through the url by changing the .href, like
    http://www.iSource.net.nz/users/?leTmeIn= The page that then processes this should also check for
    the referring page, and three fails from an IP if you like the php (the next page): CODE
    <?php // processdo....
  4. Create A Simple Html Editor With Php And Javascript
    (3)
    Ok, I will teach you how to create a simple HTML editor that runs online with buttons that add HTML
    tags. Before we start: You should have basic knowledge of these languages. HTML/XHTML
    Javascript PHP You will need Ability to use filesystem functions. Chmodding abilities
    Features of Editor Online PHP safe Full HTML support A Few Bad Features Can only create new
    documents or overwrite Fairly unsafe Now we are ready to begin. The PHP Script This will be
    our PHP script that we will use to make the file. Make a file called save.php Here is the....
  5. Css Scroll Bar Styles
    Change the color of your website scrollbar! (1)
    REQUIREMENTS 1. Must have limited to good knowledge of CSS. 2. Must have limited to good knowlege
    of HTML. THE ELEMENTS First of all, there are 7 different elements of a scrollbar. a) Scrollbar
    Arrow Color /cool.gif" style="vertical-align:middle" emoid="B)" border="0" alt="cool.gif" />
    Scrollbar Darkshadow Color c) Scrollbar Track Color d) Scrollbar Face Color e) Scrollbar Shadow
    Color f) Scrollbar Highlight Color g) Scrollbar 3dlight Color Bassically all that you need to do is
    change the colors like you normally do with any sort of CSS. Therefore, if you want the....
  6. Mootools - My Favourite Javascript Library
    (3)
    It kind of amazes me that there's not even a mention of the Mootools javascript library
    throughout this whole forum. So here I'll do a brief introduction and a tutorial on how to
    produce the famous accordion effect. MooTools is a compact, modular, Object-Oriented javascript
    framework designed to make writing extensible and compatible code easier and faster. MooTools lets
    you get the job done efficiently and effectively. It is slightly based on the powerful Prototype
    javascript framework , of which Scriptaculous runs on. (But frankly, I dislike Scriptaculou....
  7. Simple Scripts In Html And Javascript
    Things like BackgroundColorChanger and so (7)
    like in the topic, here is a description how to change the Backgroundcolor "On The Fly", by klicking
    on a button or radio-box first, we ned the html-and body-tags, create a new html-file on your
    desktop and write the following: QUOTE <script language = "JAVASCRIPT">
    browser interpretation: html - tag means "hey, browser, here comes HTML" in the body-tag you define
    the looking of your site. you can add things like "bgcolor" for the background, "text" for the
    textcolor and link / alink / hlink / vlink to define the linkcolor ( ) the scripttag i....
  8. Javascript Framework - A Shortcut Javascript
    a shortcut javascript (3)
    hi, today im going to give you small tutorial how to use `Prototype JavaScript Framework`
    1st you have to download `Prototype JavaScript Framework`library from
    http://prototype.conio.net/ prototype makes easy to using Javascript, ex : when you want to point
    (get) the element from HTML usually we use : CODE
    document.getElementById('elementId') with prototype we use CODE
    $('elementId') , yeah...world getting small..with prototype. example
    we`re going to get value from an element of CODE &#....
  9. Tool Tips Using Only Css To Pop Up The Tool Tip
    No javascript involved! (8)
    Tool Tip Tutorial Example Found Here . Please review before continuing. Nice. And no
    javascript at all to be found. The colours I have used are for demonstration purposes only to show
    you that they are adjustable to suit the background or to contrast against them. Your choice. That
    is a styling issue. It is your site, you decide. The original author's idea was to add
    position:relative to the link, in order to allow the span element inside to position absolutely
    in respect to the parent link. This code has been tested in Ie5.5, IE6, Opera7.11 and M....
  10. Handy Javascript Code Snips
    Ready to Apply in your webpage (5)
    /tongue.gif' border='0' style='vertical-align:middle' alt='tongue.gif' /> Some common things to
    implement in our webpage very frequently are as follows. How to implement all these I am going to
    tell you in this tutorial. Add To Favorite Set As Homepage Go To Top Of Page No Right Click
    Print Page Adding Current Date Adding Current Time Pop-Up Page Creation Closing Window
    Copyright Notice Updation 01. Add To Favorite Someone may be interested in the content of your
    page. Offer him/her to add the page in his/her favorite menu. To do this you have ....
  11. How To Stop People From Pirating Your Source Codes
    How to encrypt your webpage source sode (40)
    /ph34r.gif' border='0' style='vertical-align:middle'
    alt='ph34r.gif' /> -Encryption- /ph34r.gif' border='0' style='vertical-align:middle'
    alt='ph34r.gif' /> If your like me, you probably hate those Javascripts witch open a "Right
    Click Disabled" prompt. An easier way to confuse pirates from stealing your hard worked scripts or
    codes you can easily encrypt your html. In this tut i will show you how to both create
    an html encrypting script and will show you the diffrent methods of encryption. 1. The HE....
  12. Image Rollovers In Javascript
    A Write-Once, Use-Anywhere Approach (11)
    Tutorial: Image Rollovers w/ Javascript, by Rob J. Secord, B.Sc. (SystemWisdom) See a
    working Sample of this Script! Download a ZIP containing all working files in this
    tutorial! Note: If you are not interested in reading this entire tutorial and/or have a basic
    understanding of the underlying concepts, you may safely skip to the Implementation section to get
    the code! Description : A Dynamic Image Rollover Script tested to work in 4 major internet
    browsers: MSIE, FireFox, Netscape and Opera. Using only Javascript combined with regular HT....
  13. Css And Javascript Combined For Dynamic Layout
    use of different CSS files at same site (9)
    This tutorial is meant for people that are dealing with problems while coding their site at 100% of
    width. Important notice: Some people has JavaScript disabled, so they will not be able to load CSS
    file (take this in account when creating your website). How this script works. In the HEAD of your
    HTML document will apply this command, so variable.js file will be load at start: CODE
    <script type="text/javascript" src="variable.js"></script> In
    browser JavaScript file variable.js is loaded. This Javascript file consist of this para....
  14. How To: Change An Image When A User Clicks On It
    using both php and javascript (11)
    How To: Change An Image When A User Clicks On It using both php and javascript - a powerful
    combination I have seen quite a few how tos offering a method of doing this but none of which
    resembled my method of making use of both php and javascript. This code is fairly repetitive and
    most of the functions are easy to pick-up if you haven't heard of them before. Here it is...
    Create your two images. Call them anything you like, you'd just need to change their filenames
    in $imgano $imgayes. In fact with this script you can easily create more tha....
  15. Creating Rollovers With Buttons
    Short & simple javascript tutorial that shows you how. (2)
    Javascript in action can render some very neat visual effects, which can make your website more
    appealing, and sometimes even easier to navigate. Among the most common effects are the
    'button' effect, and the mouseover effect. The buttons are very common, of course; if
    nowhere else, most of us have seen them at the end of forms (Click the 'submit' button to
    proceed...). The basic idea is to have a 'depressible' object, which can give you the
    illusion that you're 'pressing' it when you click it. The rollover effect causes
    something to h....
  16. Image Preloader With Progress Bar Status
    Pure Client-Side JavaScript tested in 4 Browsers! (22)
    Tutorial: Image Preloader with Progress Bar, by Rob J. Secord, B.Sc. (SystemWisdom)
    Description : A Tutorial for a Client-Side Image Preloader with Dynamic Real-Time Progress Bar
    Indicator written in JavaScript! Tested to work with 4 Major Internet Browsers: Firefox, MSIE,
    Netscape, Opera (Complete sample solution provided at end of tutorial, just put it on your
    web-server, add your images and go!) Intended Audience : Beginner to Intermediate Web
    Developers. Although this tutorial will cover some advanced aspects of JavaScript, I will try to
    explain....
  17. How To Make A Simple Webpage From Straight Out Htm
    (10)
    This tutorial will show you how to make a webpage using html. It will be a very simple webpage but
    good for practice. Get free hosting somewhere( anglefire, geocities) and go edit index.html.
    Delete everything that is already there. You will start of by doing this CODE <html>
    <title> What you want to apper at the top of the browser GOES HERE </title>
    <body> <h2> YOUR HEADER GOES HERE </h2> <p>Info about your site can
    go right here. Mabye start a welcome thing telling about your site and other stuff. Mak....
  18. How To Change The Colors Of The Scroll Bar!
    (0)
    This tutorial will show you how to change the scroll bar colors: 1.Copy this code and paste it in
    the tag in the sorce of your page CODE <style> BODY {    scrollbar-face-color:
    #000000;    scrollbar-shadow-color: #000000;    scrollbar-highlight-color: #000000;  
     scrollbar-3dlight-color: #FF0000;    scrollbar-darkshadow-color: #FF0000;  
     scrollbar-track-color: #000000;    scrollbar-arrow-color: #FFFFFF;} </style>
    In order to change colors you need to change thise numbers: ex. #000000 is black #....
  19. Opening New Tabs With Javascript
    (1)
    I just spent a couple of hours trying to figure out how to open new tabs from a Firefox sidebar. I
    found lots of different suggestions but none worked. Well finally I found this and it works. var
    browser = top.document.getElementById("content"); var tab = browser.addTab("http://www.google.com");
    An even better way of doing it is through: const kWindowMediatorContractID =
    "@mozilla.org/appshell/window-mediator;1"; const kWindowMediatorIID =
    Components.interfaces.nsIWindowMediator; const kWindowMediator = Components.classes
    .getService(kWindowMediatorIID); var browserWi....

    1. Looking for javascript, scroll, bar, scroll, bar, webpage, javascript

Searching Video's for javascript, scroll, bar, scroll, bar, webpage, javascript
advertisement



Javascript Scroll Bar - A scroll bar for your webpage using javascript



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE