为什么我的调整大小事件没有解雇?

时间:2014-09-15 10:54:03

标签: javascript jquery css resize height

My DIV #sequence是浏览器窗口的全高,窗口大小高于920px。当它的高度大于920px我想要发射一个插件时,对于低于920px的窗口大小,我希望#sequence div是我的CSS文件中设置的高度作为后备。这在页面加载时有效,但是我无法触发resize事件,它没有响应,我在控制台中看不到任何错误。

这是我的代码,主要来自这篇文章Do something if screen width is less than 960 px

var eventFired = 0;

if ($(window).height() < 920) {

} else {
    fitSequence();  
    eventFired = 1;
}

$(window).on('resize', function() {
    if (!eventFired == 1) {
        if ($(window).height() < 920) {

        } else {
            $(window).resize(function(){ fitSequence(); });
        }
    }
});

就像这里的FYI一样,我正在引用fitSequence插件:

function fitSequence(){
var height=$(window).height();

$('#sequence').css('height',height-100+"px");
};

1 个答案:

答案 0 :(得分:2)

如果条件不正确:

if (!eventFired == 1) {

应该是:

if (eventFired != 1) {

在功能部分,这是代码的模糊部分:

$('#sequence').css('height',height-100+"px");

应该是:

$('#sequence').css('height',(height-100)+"px");
                           ^^ add brackets 
相关问题