egr103
egr103

Reputation: 3978

Why is my resize event not firing?

My DIV #sequence is to be full height of the browser window for window sizes greater than 920px in height. When its greater than 920px in height I want to fire a plugin, for window sizes lower than 920px I want the #sequence div to be the height set in my CSS file as a fallback. This works when the page is loaded, however I cannot get the resize event to fire, its unresponsive and I see no errors in console.

This is my code mostly taken from this post 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(); });
        }
    }
});

Just as an FYI here's the fitSequence plugin I'm referencing:

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

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

Upvotes: 0

Views: 1106

Answers (1)

Code Lღver
Code Lღver

Reputation: 15603

If condition is not correct:

if (!eventFired == 1) {

It should be:

if (eventFired != 1) {

And in the function part this is ambiguous part of code:

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

It should be:

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

Upvotes: 2

Related Questions