Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2. 2 * Created by IntelliJ IDEA.
  3. 3 * User: Bugi
  4. 4 * Date: 13 вер 2010
  5. 5 * Time: 13:16:06
  6. 6 * To change this template use File | Settings | File Templates.
  7. 7 */
  8. 8var rotate_timer;
  9. 9jQuery.fn.MainSlider = function()
  10. 10{
  11. 11 return this.each(function()
  12. 12 {
  13. 13 var conteiner = this;
  14. 14 var li_width = $('li:first', conteiner).innerWidth();
  15. 15 if($.browser.webkit)
  16. 16 {
  17. 17 // В хроме не может вытянуть ширину дива :(
  18. 18 li_width = 540;
  19. 19 }
  20. 20 var ul_width = $('li', conteiner).length * li_width;
  21. 21 $('ul', conteiner).css('width', ul_width);
  22. 22 var isAnimate = false;
  23. 23 var ul_left = parseInt($('ul',conteiner).css('left'));
  24. 24
  25. 25 rotate_slider(5000, conteiner);
  26. 26
  27. 27 $('.slide-prev', conteiner).click(function()
  28. 28 {
  29. 29 ul_left = parseInt($('ul',conteiner).css('left'));
  30. 30 if( !(ul_left >= 0) )
  31. 31 {
  32. 32
  33. 33 if(!isAnimate)
  34. 34 {
  35. 35 isAnimate = true;
  36. 36 $('ul', conteiner).animate({ left : ul_left + li_width +'px' } , 1000, '', function()
  37. 37 {
  38. 38 isAnimate = false;
  39. 39 });
  40. 40 }
  41. 41 }
  42. 42 });
  43. 43
  44. 44 $('.slide-next', conteiner).click(function()
  45. 45 {
  46. 46 clearInterval(rotate_timer);
  47. 47 ul_left = parseInt($('ul',conteiner).css('left'));
  48. 48 if(!isAnimate)
  49. 49 {
  50. 50 if( (-ul_left + li_width) != ul_width )
  51. 51 {
  52. 52 isAnimate = true;
  53. 53 $('ul', conteiner).animate({ left : ul_left - li_width +'px' } , 1000, '', function()
  54. 54 {
  55. 55 isAnimate = false;
  56. 56 });
  57. 57 }
  58. 58 else
  59. 59 {
  60. 60 var last_li = $('ul li:last', conteiner).clone();
  61. 61 $('ul',conteiner).prepend(last_li);
  62. 62 $('ul',conteiner).css('left', 0);
  63. 63 ul_left = parseInt($('ul',conteiner).css('left'));
  64. 64 if(!isAnimate)
  65. 65 {
  66. 66 isAnimate = true;
  67. 67 $('ul', conteiner).animate({ left : ul_left - li_width +'px' } , 1000, '', function()
  68. 68 {
  69. 69 last_li.remove();
  70. 70 $('ul', conteiner).css('left', 0);
  71. 71 isAnimate = false;
  72. 72 });
  73. 73 }
  74. 74 }
  75. 75 }
  76. 76 });
  77. 77
  78. 78
  79. 79 });
  80. 80}
  81. 81function rotate_slider(time_out, conteiner)
  82. 82{
  83. 83
  84. 84 rotate_timer = setTimeout(function()
  85. 85 {
  86. 86 $('.slide-next', conteiner).click();
  87. 87 rotate_slider(time_out, conteiner);
  88. 88 },time_out);
  89. 89}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement