script.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /**
  2. ** 公用滚动方法
  3. ** 支持定时自动轮播、前后轮播、单独点击轮播
  4. **/
  5. (function($){
  6. $("div[data-scro='controler'] b,div[data-scro='controler2'] a").click(function(){
  7. var T = $(this);
  8. if(T.attr("class")=="down") return false;
  9. J2ROLLING_ANIMATION.st({
  10. findObject : T, //当前点击对象 默认写
  11. main : T.parent().parent().find("div[data-scro='list']"), //滚动目标容器窗口对象
  12. pagSource : T.parent().parent().find("div[data-scro='controler'] b"), //切换按钮对象
  13. className : "down", //选中的样式
  14. duration : "slow", //滚动速度 和jquery速度一致
  15. on : $(this)[0].tagName=="A" ? true : false //用于判断是否开启无限滚动 or 来回切换
  16. });
  17. return false;
  18. });
  19. var J2SETTIME="", J2Time=true,J2ROLLING_ANIMATION = {
  20. init : function(){
  21. this.start();
  22. this.time();
  23. },
  24. st : function(o){
  25. if(J2Time){
  26. this.animate(o.findObject,o.main,o.className,o.duration,o.pagSource,o.on);
  27. J2Time = false;
  28. }
  29. },
  30. animate : function(T,M,C,S,P,O){
  31. var _prevDown = O ? P.parent().find("*[class='"+C+"']") : T.parent().find(T[0].tagName+"[class='"+C+"']"),
  32. _prevIndex = _prevDown.index(),
  33. _thisIndex = O ? (T.attr("class")=="next" ? _prevIndex+1 : _prevIndex-1) : T.index(),
  34. _list = M.find(".item"),
  35. p2n = 1;
  36. _prevDown.removeClass(C);
  37. if(O){
  38. if(_thisIndex==-1) _thisIndex=_list.size()-1;
  39. if(_thisIndex==_list.size()) _thisIndex=0;
  40. P.eq(_thisIndex).addClass(C);
  41. }else{
  42. T.addClass(C);
  43. }
  44. if(T.attr("class")=="prev" || _thisIndex<_prevIndex) p2n = false;
  45. if((T.attr("class")=="next" || _thisIndex>_prevIndex)&&T.attr("class")!="prev") p2n = true;
  46. !p2n ? _list.eq(_thisIndex).css("left",-M.width()) : '';
  47. _list.eq(_prevIndex).animate({left:p2n ? -M.width() : M.width()},S,function(){
  48. $(this).removeAttr("style");
  49. J2Time = true;
  50. });
  51. _list.eq(_thisIndex).animate({left:"0px"},S);
  52. },
  53. start : function(){
  54. $("#section-focus-pic div[data-scro='controler'] b,#section-focus-pic div[data-scro='controler2'] a").mouseover(function(){
  55. window.clearInterval(J2SETTIME);
  56. }).mouseout(function(){
  57. J2ROLLING_ANIMATION.time();
  58. });
  59. },
  60. time : function(){
  61. J2SETTIME = window.setInterval(function(){
  62. var num = $("#section-focus-pic div[data-scro='controler'] b[class='down']").index(),
  63. _list = $("#section-focus-pic div[data-scro='list'] li");
  64. _list.eq(num).animate({"left":-$("#section-focus-pic div[data-scro='list']").width()},"slow",function(){
  65. $(this).removeAttr("style");
  66. $("#section-focus-pic div[data-scro='controler'] b").removeClass("down").eq(num).addClass("down");
  67. });
  68. num++;
  69. if(num==_list.size()){
  70. num=0;
  71. }
  72. _list.eq(num).animate({"left":"0px"},"slow");
  73. },4000);
  74. }
  75. };
  76. $("a").click(function(){
  77. $(this).blur();
  78. });
  79. J2ROLLING_ANIMATION.init(); //是否开启自动轮播
  80. })(this.jQuery || this.baidu);