main.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. $(function(){
  2. //头部轮播图
  3. var r_num = 0;
  4. function roastingChart(){
  5. roastingChartChange();
  6. r_num++;
  7. if(r_num >= 4){
  8. r_num = 0;
  9. }
  10. }
  11. function roastingChartChange(){
  12. $(".lSPager_lists").hide();
  13. $("#lSPager_"+r_num).show();
  14. $(".lSPager_btn").css({"border":"1px solid rgba(255,255,255,0.3)","background":"rgba(0,0,0,0.3)"});
  15. $("#page_"+r_num).css({"border":" 1px solid #d0d3d5","background":"#fff"});
  16. $(".lSPager_pic").hide();
  17. $("#lSPager_pic_"+r_num).show();
  18. }
  19. //轮播计时器
  20. var timer1 = setInterval(roastingChart,2000);
  21. //点击轮播按钮
  22. $(".lSPager_btn").click(function(){
  23. clearInterval(timer1);
  24. num = $(this).index();
  25. roastingChartChange();
  26. timer1 = setInterval(roastingChart,2000);
  27. });
  28. //无缝轮播
  29. var i = 0;
  30. //克隆第一张图片,复制到列表最后
  31. //var clone = $(".promo_content_pic .promo_content_pic_lists li").first().clone();
  32. //$(".promo_content_pic .promo_content_pic_lists").append(clone);
  33. var size = $(".promo_content_pic .promo_content_pic_lists li").size();
  34. //自动轮播
  35. var t = setInterval(function () { i++; move();},2000);
  36. //向左
  37. $(".promo_content_pic .btn_l").click(function () {
  38. clearInterval(t);
  39. i++;
  40. move();
  41. t = setInterval(function () { i++; move();},2000);
  42. });
  43. //向右
  44. $(".promo_content_pic .btn_2").click(function () {
  45. clearInterval(t);
  46. i--;
  47. move();
  48. t = setInterval(function () { i++; move();},2000);
  49. });
  50. //移动事件
  51. var length = $(".promo_content_pic .promo_content_pic_lists li").width();
  52. $(window).resize(function(){
  53. length = $(".promo_content_pic .promo_content_pic_lists li").width();
  54. });
  55. function move() {
  56. if (i == size) {
  57. $(".promo_content_pic .promo_content_pic_lists").css({ left: 0 });
  58. i = 1;
  59. }
  60. if (i == -1) {
  61. $(".promo_content_pic .promo_content_pic_lists").css({ left: -(size - 1) * length });
  62. i = size - 2;
  63. }
  64. $(".promo_content_pic .promo_content_pic_lists").stop().animate({ left: -i * length }, 500);
  65. }
  66. //在线聊天
  67. $(".narrow_down_f").click(function(){
  68. $(".open_chat").hide();
  69. $(".close_chat").show();
  70. });
  71. $(".close_chat").click(function(){
  72. $(".close_chat").hide();
  73. $(".open_chat").show();
  74. });
  75. //监听滚动条上下移动,头部导航条显示
  76. var p=0,t=0;
  77. $(window).scroll(function(e){
  78. p = $(this).scrollTop();
  79. if(t<=p){//下滚
  80. $(".nav_header1").hide();
  81. $(".nav_header").hide();
  82. }else{//上滚
  83. if(p == 0){
  84. $(".nav_header1").show();
  85. $(".nav_header").hide();
  86. }else{
  87. $(".nav_header").show();
  88. $(".nav_header1").hide();
  89. }
  90. }
  91. setTimeout(function(){t = p;},0);
  92. });
  93. });