我把一个div放在调整窗口大小上,但是即使我有一个'else‘语句,这个函数仍然在执行。它不会更改为空白处-顶部: 0。flexVerticalCenter();继续覆盖它。
jQuery(document).ready(function ($) {
$(window).on("resize", function (e) {
checkScreenSize();
});
checkScreenSize();
function checkScreenSize(){
var newWindowWidth = $(window).width();
if (newWindowWidth < 1023) {
$('.v-align').flexVerticalCenter();
}
else {
$('.v-align').css('margin-top', '0');
}
}
});发布于 2017-07-18 14:52:15
注释掉if else语句中的项表明checkScreenSize正在工作,因此可能是flexVerticalCenter函数中的某些内容或某些其他css重写。
jQuery(document).ready(function ($) {
$(window).on("resize", function (e) {
checkScreenSize();
});
checkScreenSize();
function checkScreenSize(){
var newWindowWidth = $(window).width();
if (newWindowWidth < 1000) {
//$('.v-align').flexVerticalCenter();
console.log("do the flexVerticalCenter()");
}
else {
//$('.v-align').css('margin-top', '0');
console.log("do the margin-top");
}
}
});<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
https://stackoverflow.com/questions/45159347
复制相似问题