Advertisement
Guest User

Untitled

a guest
Feb 9th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1.  
  2. var maxRight = $('.gray').width() - $('.red').width();
  3. var maxLeft = 0;
  4. var img = $('.pic');
  5. var step = parseInt(maxRight/$('.pic').length);
  6.  
  7. console.log('sivo: '+$('.gray').width()+' broi: '+ $('.pic').length + ' step: '+step);
  8.  
  9. $(".flex-next").click(function(){
  10.  
  11. var marginLeft = parseInt($('.red').css('margin-left'));
  12. var marginLeftStep = marginLeft+step;
  13.  
  14. if (marginLeft == maxRight ) {
  15. $('.red').animate( {'margin-left': 0} );
  16. }
  17.  
  18. else if ( marginLeftStep > maxRight) {
  19. $('.red').animate( {'margin-left': maxRight} );
  20. }
  21.  
  22. else {
  23. $('.red').animate( {'margin-left': marginLeftStep} );
  24. }
  25.  
  26. console.log('margin-left: '+ marginLeft +' maxRight: '+maxRight);
  27.  
  28. });
  29.  
  30. $(".flex-prev").click(function(){
  31.  
  32. var marginLeft = parseInt($('.red').css('margin-left'));
  33. var marginLeftStep = marginLeft+step;
  34.  
  35. if (marginLeft == maxLeft ) {
  36. $('.red').animate( {'margin-left': maxRight} );
  37. }
  38.  
  39. else if( marginLeft < step ) {
  40. $('.red').animate( {'margin-left': 0} );
  41. }
  42.  
  43. else {
  44. $('.red').animate( {'margin-left': marginLeft-step} );
  45. }
  46. console.log('margin-left: '+marginLeft+' maxRight: '+maxRight);
  47. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement