简体   繁体   中英

execute a jQuery slideUp event when screen width exceeds a certain value

I am making a responsive site in which I add event listeners to blocks to slide down. If I resize my browser window to become wider I want to execute a slideUp to this blocks so that they're all neatly slided up. Does anyone know how to achieve this?

My jquery function:

function mobileFunctions(){

    if($(window).width() < 600){
       $(".replace-url").attr('href', '#');
       $(".list-categories li").removeClass('click');

       categoryActive();
    }  
}

function categoryActive(){

    $(".title-click").click(function(){
        var e = $(this).parent("li");
        var i = ".list-categories li";
        var c = "active";
        var d = ".content-category";

        if(!$(e).hasClass(c)){
            $(i).removeClass(c);
            $(i).children(d).slideUp("slow");
        }

        $(e).children(d).slideDown("slow");
        $(e).addClass(c);

    });

I believe you are looking for this?

$('window').resize(function() {
    var someValue = 1024;
    if ($('window').width() > someValue) {
        // function here...
    }
});

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