简体   繁体   中英

Listener for resize event

Using bootstrap collapsing menu and need to add css property to another div, when menu is collapsed. .nav-collapse inline height value changes, but the event listener doesnt work. So whats the problem? Or is there another way to make, what I want?

$('.nav-collapse').resize(function() {
            var height = $('.nav-collapse').height();
            $('.custom-class').css('margin-top', height);
        })

Elements don't have a resize event, just window .

You'll have to apply the margin-top another way, there just isn't an event to hook here. If the collapsing menu gets a class added to it or similar, you can probably use that if the other element is either a descendant or a sibling. (If it's neither, it gets really hard.)

Or you could hook the event(s) that close the collapsing menu, and handle the margin-top there (either immediately, or if the collapse is animated, after a delay).

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