简体   繁体   中英

does the jquery trigger('resize') function works only once?

I have this 2 pieces of code

function fixFooter() {
    var wrapper = $('#disqus_wrapper').height();
    if ( wrapper > 200 ) { 
        $(window).trigger('resize');
    }
};

var element = $('#disqus_wrapper');
new ResizeSensor(element, function() {
    fixFooter();
});

The expected effect is that the window will resize every time the div#disqus_wrapper changes height. (to fix comments and footer overlapping)

Well the code works, but only once after the page loads. I need it to resize each time the div changes in height. I tried switching the trigger('resize') function with an alert and everything works perfectly. Any idea why the trigger('resize') only works once and how can I fix it?

Update ;

The html is just this because I am loading the Disqus comment system

<div id="disqus_wrapper"><div id="disqus_thread"></div></div>

For detecting the div height change I am using this library https://github.com/marcj/css-element-queries (the ResizeSensor.js)

You need to call your function fixFooter() in window resize event.

    $( window ).resize(function() {
       fixFooter();
    });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM