Advertisement
Guest User

rotator

a guest
Jan 15th, 2013
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var intervalId;
  2. var bgPosition = {
  3.     x: 0,
  4.     y: 0
  5. };
  6.  
  7. var pixelOffset = 160;
  8. var maxCycle    = 10;
  9. var i           = 0;
  10.  
  11. function scrollBackground(id) {
  12.         if (i == maxCycle){
  13.             i = 0;
  14.         }
  15.         bgPosition.x = i * pixelOffset;
  16.         i++;
  17.  
  18.     $('.rotator').css('background-position', bgPosition.x + 'px ' + bgPosition.y + 'px');
  19. }
  20.  
  21. function setBakcgroundToDefault() {
  22.    
  23.     $('.rotator').css('background-position', 0 + 'px ' + 0 + 'px');
  24. }
  25.  
  26. $(document).ready(function () {
  27.     $('.rotator').hover(function () {
  28.         var intervalDelay = 500;
  29.         var currentID = $(this).attr('id');
  30.         intervalId = setInterval(scrollBackground(currentID), intervalDelay);
  31.     }, function () {
  32.         setBakcgroundToDefault();
  33.         clearInterval(intervalId);
  34.     });
  35.  
  36. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement