zono

scroller.js

May 5th, 2012
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * This file is writen by Georgi Naumov
  3.  * [email protected] for contacts and
  4.  * suggestions.
  5.  **/
  6.  
  7. /**
  8.  * I try to made a
  9.  * scroller 'object'.
  10.  */
  11. var scroller = (function(){
  12.       var intervalId = null;
  13.       var divToScroll = null;
  14.       var maxScroll = null;
  15.  
  16.       return {
  17.          
  18.           startScroll : function() {
  19.               /**
  20.                * Protect from several scroll startups
  21.                */
  22.               if(intervalId != null) {
  23.                   return false;
  24.               }
  25.               divToScroll = document.getElementById("scroller");
  26.               /**
  27.                * 4 - size ot borders for every side.
  28.                **/
  29.               maxScroll = divToScroll.scrollWidth - divToScroll.offsetWidth + 8;
  30.               intervalId = setInterval(function() {
  31.                   if(divToScroll.scrollLeft == maxScroll) {
  32.                       divToScroll.scrollLeft = 0;
  33.                   }
  34.                   divToScroll.scrollLeft += 20;
  35.               }, 500);
  36.           },
  37.          
  38.           stopScroll : function() {
  39.               /**
  40.                * If intervalId is null we don't
  41.                * need to clear it.
  42.                */
  43.               if(intervalId == null) {
  44.                   return false;
  45.               }
  46.               clearInterval(intervalId);
  47.               intervalId = null;
  48.           }
  49.       }
  50. })();
  51.  
  52. scroller.startScroll();
Advertisement
Add Comment
Please, Sign In to add comment