尝试向此添加调整大小函数,以允许此脚本底部的if else语句根据窗口宽度进行刷新和调整大小。除非单击英雄上的向下箭头按钮,否则所有内容都可以正常工作。偏移顶部值不会在调整大小时更新。不知道如何正确执行调整大小函数更新
目前文稿中的地方 -
$(function() {
var windowW = $(window).width();
$('a[href*="#"]:not([href="#"])').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if ((target.length) && (windowW > 770)) {
$('html, body').animate({
scrollTop: (target.offset().top) + 2
}, 450);
return false;
} else {
$('html, body').animate({
scrollTop: (target.offset().top) - 86
}, 450);
return false;
}
}
});
});
事情我已经尝试过 - 这接缝打破它。
$(window).resize(function(e) {
var windowW = $(window).width();
$('a[href*="#"]:not([href="#"])').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if ((target.length) && (windowW > 770)) {
$('html, body').animate({
scrollTop: (target.offset().top) + 2
}, 450);
return false;
} else {
$('html, body').animate({
scrollTop: (target.offset().top) - 86
}, 450);
return false;
}
}
});
});
DEV LINK http://www.alexcoven.com/dev/element
你需要刷新整个脚本吗?看起来就像'windowW'变量应该做的那样? – Sam0
是啊,只是winowW变量 – alcoven