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);
        })
      }
    }
  })

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM