public.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. var lock=false;
  22. function playnext(){
  23. $ct.animate({marginLeft:'-='+mov*imgWidth},function(){
  24. curidx++;
  25. if(curidx===imgCount){
  26. $ct.css({marginLeft:0-imgWidth});
  27. curidx=0;
  28. }
  29. })
  30. $('.index_tt .banner_txt').eq(curidx).show().siblings().hide();
  31. }
  32. function playpre(){
  33. $ct.animate({marginLeft:'+='+mov*imgWidth},function(){
  34. curidx--;
  35. if(curidx===(-1)){
  36. $ct.css({marginLeft:0-imgWidth*imgCount});
  37. curidx=3;
  38. }
  39. })
  40. $('.index_tt .banner_txt').eq(curidx).show().siblings().hide();
  41. }
  42. var timer=setInterval(playnext,3000)
  43. $('.banner').mouseenter(function(){
  44. clearInterval(timer)
  45. })
  46. $('.banner').mouseleave(function(){
  47. timer=setInterval(playnext,3000)
  48. })
  49. $('.img_list ol li').hover(function(){
  50. var simg = $(this).children('img').attr('src')
  51. $('.banner_box ul li').eq(curidx+1).find('img').attr('src',simg)
  52. })
  53. //导航
  54. $(window).scroll(function(){
  55. var scrolltop=$(document).scrollTop()
  56. if(scrolltop>400){
  57. $('header').addClass('h_fix')
  58. $('body').css({paddingTop:'74px'})
  59. }else{
  60. $('header').removeClass('h_fix')
  61. $('body').css({paddingTop:0})
  62. }
  63. });
  64. })