public.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. $(function(){
  2. $('.index_tt .banner_txt').eq(0).show().siblings().hide();
  3. var $ct=$('.banner_box ul'),
  4. $items=$ct.children(),
  5. $pre=$('.index_pre'),
  6. $next=$('.banner_next'),
  7. imgCount=$items.length,
  8. imgWidth=$items.width();
  9. $ct.append($items.first().clone());
  10. $ct.prepend($items.last().clone());
  11. var newCount=$ct.children().length;
  12. $ct.css({marginLeft:0-imgWidth,width:newCount*imgWidth});
  13. $next.on('click',function(){
  14. playnext();
  15. })
  16. $pre.on('click',function(){
  17. playpre();
  18. })
  19. var curidx =0;
  20. var mov = 1;
  21. function playnext(){
  22. $ct.animate({marginLeft:'-='+mov*imgWidth},1000,function(){
  23. curidx+=mov;
  24. if(curidx===imgCount){
  25. $ct.css({marginLeft:0-imgWidth});
  26. curidx=0;
  27. }
  28. })
  29. $('.index_tt .banner_txt').eq(curidx).show().siblings().hide();
  30. }
  31. function playpre(){
  32. $ct.animate({marginLeft:'+='+mov*imgWidth},1000,function(){
  33. curidx-=mov;
  34. if(curidx<0){
  35. $ct.css({marginLeft:0-imgWidth*imgCount});
  36. curidx=imgCount-1;
  37. }
  38. })
  39. $('.index_tt .banner_txt').eq(curidx).show().siblings().hide();
  40. }
  41. var timer=setInterval(playnext,3000)
  42. $('.banner').mouseenter(function(){
  43. clearInterval(timer)
  44. })
  45. $('.banner').mouseleave(function(){
  46. timer=setInterval(playnext,3000)
  47. })
  48. $('.img_list ol li').hover(function(){
  49. var simg = $(this).children('img').attr('src')
  50. $('.banner_box ul li').eq(curidx+1).find('img').attr('src',simg)
  51. })
  52. //导航
  53. $(window).scroll(function(){
  54. var scrolltop=$(document).scrollTop()
  55. if(scrolltop>400){
  56. $('header').addClass('h_fix')
  57. $('body').css({paddingTop:'74px'})
  58. }else{
  59. $('header').removeClass('h_fix')
  60. $('body').css({paddingTop:0})
  61. }
  62. });
  63. //挂件
  64. $('.pendent_box').click(function(e){
  65. e.preventDefault();
  66. $("body,html").animate({scrollTop:0},1000)
  67. });
  68. // $(window).scroll(function(){
  69. // var scrolltop=$(document).scrollTop()
  70. // if(scrolltop>700){
  71. // $('.pendent_box').fadeIn(200);
  72. // }else{
  73. // $('.pendent_box').fadeOut(200);
  74. // }
  75. // });
  76. })