【发布时间】:2016-12-24 05:36:03
【问题描述】:
我正在尝试在网站上制作响应式导航栏。我有一个脚本正在运行以向导航栏添加一些效果。但是当窗口大小小于 700 像素时,我想停止我对导航栏所做的一切,并执行另一个脚本。我正在为移动设备执行此操作,但也我希望在用户缩小窗口大小时发生这种情况。
我的问题是:当宽度 > 700px 时没问题,但是当我将大小调整到小于 700px 时,脚本仍在运行,我不希望这样。
如果页面首先加载宽度小于 700px 也可以,但这并不能解决问题。
我的脚本在这里带有JSFIDDLE:
var WindowWidth = $(window).width();
$(document).ready(function($) {
handleNav();
$(window).resize(function() {
//here i call the function again after i resize to check if the condition of window width > 700px is stil true
WindowWidth = $(window).width();
handleNav();
});
});
function handleNav() {
if (WindowWidth > 700) {
$(document).scroll(function() {
if (300 / $(document).scrollTop() > 0.5 && $(document).scrollTop() > 100) {
$('#abs-header').css({
'opacity': (500 / ($(document).scrollTop() + 1))
});
$('#abs-header').css({
'background-color': 'rgba(113, 20, 20,1)'
});
}
if ($(document).scrollTop() < 100) {
$('#abs-header').css({
'background-color': 'transparent'
});
}
});
} else {
//Other code here that i didn't make yet but I want to hapen when the window is less than 700px wide.
}
}
我尝试了多种方法,但都没有奏效。我真的需要你的帮助!
【问题讨论】:
标签: javascript jquery menu responsive-design navbar