Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 140762

jQuery slideUp("slow"), but always show for Desktop screen

$
0
0

I am trying to animate $("#somediv").slideDown("slow"); and $("#somediv").slideUp("slow"); But when it slideUp() and you make the screen bigger, it keeps hidden.

Example:

function toggle() {
    $("#somediv").slideUp("2000");
}
/* Desktop */
@media only screen and (min-width: 1px) {
    #somediv {
        display: block;
        /* More styling */
    }
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script><a href="javascript:void(0);" onclick="toggle()">TOGGLE</a><div id="somediv">Div</div>

I've searched on the internet but couldn't find a solution.
Is this possible?

Thanks for helping!

SOLVED For the people with the same problem:

        function toggle() {
            if($("#somediv").css('display') == "none") {
                $("#somediv").slideDown("2000");
            }else {
                $("#somediv").slideUp("2000");
            }
        }
        $(window).on("resize",function(){  
            if (window.matchMedia('(min-width: 800px)').matches) {
                $("#somediv").show();
            }else {
                $("#somediv").hide();
            }
        });

Viewing all articles
Browse latest Browse all 140762

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>