zoukankan      html  css  js  c++  java
  • 解决jquery animate({scrollTop$pos},500)与$(window).scroll方法冲突的问题

    当点击节点时 先移除$(window).on("scroll")监听事件 在animate动画结束之后再添加上

     1 $('#J_tab li').on('click', function(){
     2         
     3             $(window).off(".changeCityActive");
     4 
     5             $('html,body').animate({scrollTop:$('.list-item-wrp[data-city="'+cityName+'"]:first').offset().top-offTop}, 400, 'easeOutExpo', function(){
     6                 $(window).on("scroll.changeCityActive" , changeCityActive);
     7             });
     8  });
     9 
    10  $(window).on("scroll.changeCityActive" , changeCityActive);
    11 
    12   function changeCityActive(){
    13       var shTop = $('.list-item-wrp[data-city="shanghai"]:first').offset().top;
    14       var hzTop = $('.list-item-wrp[data-city="hangzhou"]:first').offset().top;
    15       var szTop = $('.list-item-wrp[data-city="suzhou"]:first').offset().top;
    16       var njTop = $('.list-item-wrp[data-city="nanjing"]:first').offset().top;
    17       var qtTop = $('.list-item-wrp[data-city="qita"]:first').offset().top;
    18 
    19       if ($("#rank-wrp").css("position") == "fixed" && $(window).scrollTop() < hzTop -130) {
    20 
    21           $("#J_tab li[data-city='shanghai']").addClass('active').siblings().removeClass('active');
    22       }else if ($(window).scrollTop() >= hzTop-130 && $(window).scrollTop() < szTop-130){
    23 
    24           $("#J_tab li[data-city='hangzhou']").addClass('active').siblings().removeClass('active');
    25       }else if ($(window).scrollTop() >= szTop-130 && $(window).scrollTop() < njTop-130){ 
    26 
    27           $("#J_tab li[data-city='suzhou']").addClass('active').siblings().removeClass('active');
    28       }else if($(window).scrollTop() >= njTop-130 && $(window).scrollTop() < qtTop-130){ 
    29 
    30           $("#J_tab li[data-city='nanjing']").addClass('active').siblings().removeClass('active');
    31       }else if($(window).scrollTop() > qtTop-130){ 
    32 
    33           $("#J_tab li[data-city='qita']").addClass('active').siblings().removeClass('active');
    34       }
    35   }
  • 相关阅读:
    python模块之cx_Oracle
    python模块之xml.etree.ElementTree
    CentOS7.4 安装 oracle12c
    Markdown语法整理
    ansible command模块将返回值写入变量
    pip安装模块时:error: command 'gcc' failed with exit status 1
    The hub and spoke model 轮辐模型/辐射模型
    ActiveMQ-Network of brokers集群模式
    ansible安装配置及最佳实践roles
    ansible报错Aborting, target uses selinux but python bindings (libselinux-python) aren't installed
  • 原文地址:https://www.cnblogs.com/jingh/p/6265029.html
Copyright © 2011-2022 走看看