zoukankan      html  css  js  c++  java
  • angular浏览器滚动条滚动到指定element 触发事件

    angular.module('app').directive('ScrollTrigger', () => {
        return {
          restrict: "A",
          link:function ($scope,$element,$attrs,$controller) {
            function debounce(fn, delay) {
              let timer = null;
              return function () {
                let context = this;
                let args = arguments;
                clearTimeout(timer);
                timer = setTimeout(function () {
                  fn.apply(context, args);
                }, delay);
              }
            }
            let trigger=debounce(() => {
              if ($element.is(":hidden")) {
                return;
              }
              if (($(window).scrollTop() + $(window).height()) > ($element.offset().top + 5)) {
                if (!$scope.$eval($attrs.zScrollTrigger)) {
                  $element.trigger("click");
                }
              }
            }, 100);
            $(window).scroll(trigger);
            $scope.$on("destroy",()=>{
              $(window).unbind("scroll",trigger);
            })
          }
        }
      })
  • 相关阅读:
    HTML5 h1多层次样式问题
    spellcheck
    Favicon
    设计模式
    CSS 宽高的计算
    行高计算
    White-space 属性
    简约插件Plug-in for simple
    js类型及其判断
    前端路由
  • 原文地址:https://www.cnblogs.com/Zoes/p/6553798.html
Copyright © 2011-2022 走看看