1. // Simple JavaScript Rotating Banner Using jQuery
  2. // www.mclelun.com
  3. var jqb_vCurrent = 0;
  4. var jqb_vTotal = 0;
  5. var jqb_vDuration = 10000;
  6. var jqb_intInterval = 0;
  7. var jqb_vGo = 1;
  8. var jqb_vIsPause = false;
  9. var jqb_tmp = 20;
  10. var jqb_title;
  11.  
  12. jQuery(document).ready(function() {
  13. jqb_vTotal = $(".jqb_slides").children().size() -1;
  14. $(".jqb_info").text($(".jqb_slide").attr("title"));
  15. jqb_intInterval = setInterval(jqb_fnLoop, jqb_vDuration);
  16.  
  17. var $thumb_container = $(document.createElement('div')).addClass('jqb_thumb_container')
  18. $thumb_container.appendTo('.jqb_bar');
  19.  
  20. $("#jqb_object").find(".jqb_slide").each(function(i) {
  21. jqb_tmp = ((i - 1)*970) - ((jqb_vCurrent -1)*970);
  22. $(this).css("left", jqb_tmp+"px");
  23.  
  24. var thumb_url = $(this).find('img').attr('src');
  25. var $thumb = $(document.createElement('div')).addClass('jqb_thumb').data('thumb_number', i).click(function(){
  26. clearInterval(jqb_intInterval);
  27. jqb_vIsPause = true;
  28. $("#btn_pauseplay").removeClass("jqb_btn_pause").addClass("jqb_btn_play");
  29. jqb_vCurrent = $(this).data('thumb_number') -1;
  30. jqb_fnLoop();
  31. });
  32. var $thumb_img = $(document.createElement('img')).attr({
  33. src: thumb_url,
  34. width: 94,
  35. height: 46
  36. });
  37. $thumb_img.appendTo($thumb);
  38. $thumb.appendTo($thumb_container);
  39. });
  40.  
  41.  
  42. $("#btn_pauseplay").click(function() {
  43. if(jqb_vIsPause){
  44. jqb_fnChange();
  45. jqb_vIsPause = false;
  46. $("#btn_pauseplay").removeClass("jqb_btn_play");
  47. $("#btn_pauseplay").addClass("jqb_btn_pause");
  48. } else {
  49. clearInterval(jqb_intInterval);
  50. jqb_vIsPause = true;
  51. $("#btn_pauseplay").removeClass("jqb_btn_pause");
  52. $("#btn_pauseplay").addClass("jqb_btn_play");
  53. }
  54. });
  55. $("#btn_prev").click(function() {
  56. jqb_fnChange();
  57. jqb_vGo = -1;
  58. });
  59.  
  60. $("#btn_next").click(function() {
  61. jqb_fnChange();
  62. jqb_vGo = 1;
  63. });
  64. });
  65.  
  66. function jqb_fnChange(){
  67. clearInterval(jqb_intInterval);
  68. jqb_intInterval = setInterval(jqb_fnLoop, jqb_vDuration);
  69. jqb_fnLoop();
  70. }
  71.  
  72. function jqb_fnLoop(){
  73. if(jqb_vGo == 1){
  74. jqb_vCurrent == jqb_vTotal ? jqb_vCurrent = 0 : jqb_vCurrent++;
  75. } else {
  76. jqb_vCurrent == 0 ? jqb_vCurrent = jqb_vTotal : jqb_vCurrent--;
  77. }
  78.  
  79. $("#jqb_object").find(".jqb_slide").each(function(i) {
  80.  
  81. if(i == jqb_vCurrent){
  82. jqb_title = $(this).attr("title");
  83. $(".jqb_info").animate({ opacity: 'hide', "left": "-50px"}, 250,function(){
  84. $(".jqb_info").text(jqb_title).animate({ opacity: 'show', "left": "0px"}, 500);
  85. });
  86. }
  87.  
  88.  
  89. //Horizontal Scrolling
  90. jqb_tmp = ((i - 1)*970) - ((jqb_vCurrent -1)*970);
  91. $(this).animate({"left": jqb_tmp+"px"}, 1000);
  92.  
  93. /*
  94. //Fade In & Fade Out
  95. if(i == jqb_vCurrent){
  96. $(".jqb_info").text($(this).attr("title"));
  97. $(this).animate({ opacity: 'show', height: 'show' }, 500);
  98. } else {
  99. $(this).animate({ opacity: 'hide', height: 'hide' }, 500);
  100. }
  101. */
  102.  
  103. });
  104.  
  105.  
  106. }
  107.