$(window).scroll(function()监听滚动事件不执行

<script type="text/javascript">
    $(function(){
        $(".sex-items a,.color-items a").click(function(){
            if (!$(this).hasClass('active')) {
                $(this).parent().siblings().find("a").removeClass("active");
                $(this).addClass("active");
            } else {
                $(this).removeClass("active");
            }
        })
        $(".nature-items a").click(function(){
            var $this = $(this);
            $this.hasClass('active')
                    ? $this.removeClass('active')
                    : $this.addClass("active");
            if($this.attr("name")=="qt"){
                var $remarkInput = $this.parent().siblings().find("input");
                if ($this.hasClass('active')) {
                    $remarkInput.css("display","block");
                } else {
                    $remarkInput.css("display","none");
                }
            }
        })
    })
</script>
<script type="text/javascript">
    var img = document.getElementById("img");
    var num = document.getElementById("num");
    var ali = img.getElementsByTagName("li");
    var oli = num.getElementsByTagName("li");
    var time = 3000;
    zzscing = document.getElementById("zzsc");
    img.style.width = ali.length * 668 + "px", inow = 0;
    for (var i = 0; i < oli.length; i++) {
        oli[i].index = i
        oli[i].onmouseover = function() {
            inow = this.index;
            tab();
            window.clearInterval(time)
        }
        oli[i].onmouseout = function() {
            time = window.setInterval(autoPlay, 3500)
        }
    }
    function tab() {
        for (var i = 0; i < oli.length; i++) {
            oli[i].className = ""
        }
        oli[inow].className = "hover"
        startMove(img, {
            left: -inow * 668
        }, 'buffer')
    }

    function autoPlay() {
        inow++;
        if (inow >= ali.length) {
            inow = 0
        }
        tab();
    }
    time = window.setInterval(autoPlay, 3500);
    $(function(){
        $(window).scroll(function(){

        })
    })
</script>
$(function () {
  $(".click").click(function () {
/*    $(this).css("background", "none")*/
    $(".display").css("display", "none");
    var x = $(this).attr("name");
    switch (x) {
        case "1":

            break;
        case "2":

            break;
        case "3":
            $(".buss").toggle();
            break;
        case "5":
            $(".yj").toggle();
            break;
        case "7":
            /*    $(".demo").css("left",$(".leftdiv").width())
             $(".demo").css("display", "block")*/
            break;
        case "8":
            $(".bussiness").css("left",($(".leftdiv").width()+20))
            $(".bussiness").toggle();
            break;
    }

  })

    $(function(){
        $(".dh2").hover(function() {
            $(".rights").removeClass("rights");
            $(this).parent().addClass("rights");
            $(".demo").show();
        });
        $(".demo").mouseleave(function() {
           $(".demo").hide();
        });
    })

    $(".pic_list").height($(".rightdiv").height());
    $(".pic_list li").height($(".rightdiv").height());
    $(".pic_list li img").height($(".rightdiv").height());
    $(".demo").css("left",$(".leftdiv").width());
    $(window).resize(function(){
    $(".pic_list").height($(".rightdiv").height());
    $(".pic_list li").height($(".rightdiv").height());
    $(".pic_list li img").height($(".rightdiv").height());

    });

  $(".qd").click(function () {
    if ($(this).attr("name") == 1) {
      $(this).parent().parent().css("display", "none");
    } else {
      $(this).parent().css("display", "none");
    }
  })
  $(".list li a").click(function () {
    $(".list li").removeClass("rights");
    $(this).parents().addClass("rights")
  })
})


    $(".closes").click(function(){
       $(this).parent().css("display","none");
    })
  //初始化地区的select
  initArea('sell_province', 'sell_city', 'sell_district');
  initArea('buy_province', 'buy_city', 'buy_district');

  $('#sug_btn').click(function() {
    var name = $('#sug_name').val();
    var contact = $('#sug_contact').val();
    var content = $('#sug_content').val();

    $.post('/suggest', {
      name: name,
      contact: contact,
      content: content
    }, function(data) {
      if (data.success) {
        swal('', '提交成功,感谢您的意见!', 'success');
      } else {
        swal('', data.err_msg, 'error');
      }
      $('#sug_form')[0].reset();
    }, 'json');
  });

$('#sell_btn').click(function() {
  var category = $('#sell_cate').val();
  var birth = $('#sell_birth').val();
  var count = $('#sell_count').val();
  var vaccine = $('#sell_vaccine').val();
  var price = $('#sell_price').val();
  var name = $('#sell_name').val();
  var province = $('#sell_province').find("option:selected").text();
  var city = $('#sell_city').find("option:selected").text();
  var district = $('#sell_district').find("option:selected").text();
  var address = $('#sell_address').val();
  var phone = $('#sell_phone').val();
  var qq = $('#sell_qq').val();

  if (!count.match(/\d/)) {
    swal('数量必须为数字');
    return;
  } else if (!$('#sell_district').val()) {
    swal('请选择地区');
    return;
  }

  $.post('/regSeller', {
    category: category,
    birthday: birth,
    count: count,
    vaccine: vaccine,
    price: price,
    name: name,
    area: [province, city, district].join(' '),
    address: address,
    phone: phone,
    qq: qq
  }, function(data) {
    if (data.success) {
      swal('', '提交成功,我们会尽早与您取得联系', 'success');
    } else {
      swal('', data.err_msg, 'error');
    }
    $('#sell_form')[0].reset();
  }, 'json');

});

$('#buy_btn').click(function() {
  var category = $('#buy_category').val();
  var name = $('#buy_name').val();
  var province = $('#buy_province').find("option:selected").text();
  var city = $('#buy_city').find("option:selected").text();
  var district = $('#buy_district').find("option:selected").text();
  var address = $('#buy_address').val();
  var phone = $('#buy_phone').val();
  var qq = $('#buy_qq').val();

  if (!$('#buy_district').val()) {
    swal('请选择地区');
    return;
  }

  $.post('/regBuyer', {
    category: category,
    name: name,
    area: [province, city, district].join(' '),
    address: address,
    phone: phone,
    qq: qq
  }, function(data) {
    if (data.success) {
      swal('', '提交成功,我们会尽早与您取得联系', 'success');
    } else {
      swal('', data.err_msg, 'error');
    }
    $('#buy_form')[0].reset();
  }, 'json');
});

我jq和js的技术都不怎么样,连最后尝试了是否是$冲突发现也没办法找到问题,求技术大神能看一下是哪里的问题吗??

阅读 25.4k
2 个回答

html,body的高度样式如果设置为100%,$(window).scroll方法将检测不到正确的滚出高度(0),导致滚动监听事件失效,设置html,body{height:auto}可以解决。
刚刚遇到这个问题,已经解决,顺便MARK下。

只针对$(window).scroll,应该是$(document).scroll

宣传栏