ホバーするとjQueryアニメーションをトリガーするこのナビゲーションを作成しようとしています。ブラウザ ウィンドウが 995 ピクセル未満の場合、ホバー機能を削除しようとしています。ブラウザをリロードしたときにのみ、ウィンドウのサイズ変更に関する機能は削除されません。
$(window).resize(function() {
if ($(this).width() > 995) {
$("#main-nav a").hover(function() {
if (!$(this).hasClass('active')) {
$(this).dequeue().stop().animate({
padding: "2px 4px 0px 83px",
backgroundColor: "#47c7ee",
color: "#ffffff"});
}
}, function() {
if (!$(this).hasClass('active')) {
$(this).addClass('animated').animate({
padding: "2px 4px 0 53px",
backgroundColor: "#ffffff",
color: "#a9a9a9"
},
"normal", "linear", function() {
$(this).removeClass('animated').dequeue();
$(".active").css({
"background-color": "#47c7ee",
"color": "#ffffff",
"padding": "2px 4px 0px 83px"
});
});
}
});
}
});
次に、ウィンドウのリロード時にここで呼び出しています。
$(document).ready(function() {
$(window).resize();
});
なぜ、どのように修正する必要があるのか わからないようです。