レスポンシブ テンプレートを作成していますが、画面のサイズが変更されているか、指定された幅よりも小さい場合に、要素のリスナーを削除したいと考えています。
アイテムにカーソルを合わせると、通常の表示ではサブメニューが表示されますが、モバイル デバイスの同じメニューでは、アイテムをタップまたはクリックするだけでサブメニューが表示されるメニューを想像してみてください。
委任されていない人を働かせることはできません。mouseover
サイズ変更された画面には、mouseout
イベントリスナーがまだあります。コンソールにエラーが表示されず、両方を試しました:
.off('mouseover', 'li')
.off('mouseover')
.undelegate('li', 'mouseover')
.undelegate('li')
そして、それらのどれも機能しません。
var $window = $(window);
function handleSidenav() {
$(".nav-list").delegate('li', 'mouseover', function(e) {
$(this).find("a").addClass('active');
$(this).find("div.sub-items").toggle();
}).delegate('li', 'mouseout', function(e) {
$(this).find('a').removeClass('active');
$(this).find("div.sub-items").toggle();
});
}
function checkWidth() {
var windowsize = $window.width();
if (windowsize < 767) {
smallScreenDelegation();
} else {
SmallScreenUndelegation();
}
}
checkWidth();
handleSidenav();
$window.resize(checkWidth());
function smallScreenDelegation() {
$(".nav-list").undelegate('li'); //It's not working
$(".nav-list").undelegate('li'); //It's not working
$(".nav-list").delegate('li a:first', 'click', function(event) {
if ($(this).next().is(':hidden')) {
$(this).addClass('active');
$(this).next().slideDown('slow');
} else {
$(this).removeClass('active').next().slideUp('slow');
}
event.preventDefault();
});
}