base.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. $(function () {
  2. // menu
  3. $(".m-header i").click(function () {
  4. $(".mob-navigation").addClass("on");
  5. $("body").css('overflowY','hidden');
  6. });
  7. $(".mob-navigation .home").click(function () {
  8. $(".mob-navigation").removeClass("on");
  9. $("body").css('overflowY','scroll');
  10. });
  11. $('.free-tel,.zixun').click(function () {
  12. document.getElementById('liuyanForm').reset();
  13. $(".spot-bg").css("display", "block");
  14. $('.fixed-foot').addClass('fixed-foot-on');
  15. })
  16. $(".spot-bg,.fixed-foot i").click(function () {
  17. $(".spot-bg").css("display", "none");
  18. $('.fixed-foot').removeClass('fixed-foot-on');
  19. })
  20. $(".trade-nav-l ul li").click(function(){
  21. var index = $(this).index();
  22. console.log(index)
  23. $(this).addClass('on').siblings().removeClass('on');
  24. $(".trade-nav-r .trade-list-box").eq(index).addClass('on').siblings().removeClass('on');
  25. })
  26. /*$("img").each(function(k,item){
  27. var _this = $(this);
  28. var src = _this.attr('data-src');
  29. if(src){
  30. setTimeout(function(){
  31. _this.attr('src', src);
  32. },1)
  33. }
  34. })*/
  35. var num = document.getElementsByTagName('img').length;
  36. var img = document.getElementsByTagName("img");
  37. var n = 0; //存储图片加载到的位置,避免每次都从第一张图片开始遍历
  38. lazyload();
  39. function lazyload() { //监听页面滚动事件
  40. var seeHeight = document.documentElement.clientHeight; //可见区域高度
  41. var scrollTop = document.documentElement.scrollTop || document.body.scrollTop; //滚动条距离顶部高度
  42. for (var i = n; i < num; i++) {
  43. if (img[i].offsetTop < seeHeight + scrollTop) {
  44. var src = img[i].getAttribute("src");
  45. if (src == "" || typeof(src) == 'undefined' || src==null) {
  46. img[i].src = img[i].getAttribute("data-src");
  47. }
  48. n = i + 1;
  49. }
  50. }
  51. }
  52. // 回顶部
  53. $('.go-top').click(function () {
  54. $('body,html').animate({ scrollTop: 0 });
  55. })
  56. $(window).scroll(function () {
  57. var oTop = document.body.scrollTop == 0 ? document.documentElement.scrollTop : document.body.scrollTop;
  58. if (oTop > 200) {
  59. $('.go-top').fadeIn();
  60. } else {
  61. $('.go-top').fadeOut();
  62. }
  63. })
  64. })