遇到的问题

发表于 2018-11-20 | 标签: 浏览器

某个元素是否到了浏览器顶部 滚定监听?

 $(window).scroll(function() {
        var top1 = $('#table').offset().top;
        var gun = $(document).scrollTop();
        var top = top1-gun;
        if (top <= 0) {
          $('#table'.addClass('fixed_top');
        }else{
          $('#table').removeClass('fixed_top');
        }
      }); 

让滚动条滚动到正好显示某个节点的位置?


1、计算滚动距离: var scrollTopPx = (′定位到的节点′).offset().top−(′定位到的节点′).offset().top−(‘第一个节点’).offset().top;
 2、滚动条滚动: (′带滚动条的容器′).scrollTop(scrollTopPx);如果想用动画效果,可以用:(′带滚动条的容器′).scrollTop(scrollTopPx);如果想用动画效果,可以用:(‘带滚动条的容器’).animate({scrollTop: scrollTopPx}, 1000); // 1000毫秒滚动到该位置

babel 配置

.babelrc
{
    "presets":["es2015","stage-0"],
      "plugins":[
      "transform-remove-strict-mode"
    ]
  }