umbriel
umbriel

Reputation: 751

JQuery add class during resize event. Remove class after resize event

I want to edit the css of a div element during .resize() event and after the resize event revert to the default css properties.

To add context: Say I want set display:none; to a fullscreen image gallery while I resize the browser window. But after I stopped resizing (timeout?) fade the content back in.

Or toggle class on resize.

Hope you'll understand! Best regards

Upvotes: 0

Views: 960

Answers (1)

Gavriel
Gavriel

Reputation: 19237

timer = 0;
function start() {
    $("#id").addClass("resizing");
}
function stop() {
    $("#id").removeClass("resizing");
}
$(window).resize(function(){
    if (timer) {
        clearTimeout(timer);
    }
    timer = setTimeout(stop, 1000);
    start();
});

Upvotes: 1

Related Questions