gpt4 book ai didi

javascript - 从指令中删除事件监听器 - Angular.js

转载 作者:行者123 更新时间:2023-11-29 19:30:10 25 4
gpt4 key购买 nike

我在从鼠标滚轮和滚轮中删除事件监听器时遇到问题。我正在使用 fullpage.js 插件。

问题是,当我通过单击链接(我正在使用 angular.js 的 ui 路由器)从我的“关于页面”转到另一个页面,然后单击后退按钮返回到关于页面时,事件监听器mousewheel 和 wheel 没有被移除,并且附加了一个额外的监听器。重复这些步骤添加更多的听众。

.directive('dfAboutPagesView', function(  ) {
return {
restrict: 'A',
link: function(scope, element, attrs) {
scope.checkPackages = {
all: false
};

scope.$on("$destroy", function() {
$(document).off();
});

var fullpage_in = function () {

element.fullpage({
scrollingSpeed: 500,
autoScrolling: false
});
element.fullpage({
onLeave: function (index, nextIndex, direction) {
if (index == 1 && direction == 'down') {
$('#header').slideUp(500, 'easeInQuad');
}
else if (index == 2 && direction == 'up') {
$('#header').slideDown(500, 'easeInQuad');
}
else if (index == 3 && direction == 'down') {
$('#footer').slideDown(500, 'easeInQuad');
}
else if (index == 4 && direction == 'up') {
$('#footer').slideUp(500, 'easeInQuad');
}
}
});
};
fullpage_in();
}
}
})

最佳答案

查看 fullPage.js 的文档,我认为您想调用插件的 destroy $destroy 处理程序中的方法:

scope.$on("$destroy", function() {
$.fn.fullpage.destroy('all');
});

关于javascript - 从指令中删除事件监听器 - Angular.js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28296321/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com