How to call?

I have a small piece of code that I want to call when windows reach 640 pixels. or lower I have tried many different sentences that I found here or somewhere else, but none of them work.

$(function() {
    $('p').css('display','none');
        $('h1').click(function(){
            $('p').stop(true,true).slideToggle(1000);
    });
});
+4
source share
1 answer

You can bind window resizing events by doing the following:

$(window).on('resize', function(event){
// Do stuff here
});

You can get the window size by following these steps:

var windowWidth = $(window).width();
if(windowWidth < 640){
    // Do stuff here
}

So your function will work as follows:

$(window).on('resize', function(event)
    {
       var windowWidth = $(window).width();
       if(windowWidth < 640){
       $('p').css('display','none');
           $('h1').click(function(){
               $('p').stop(true,true).slideToggle(1000);
       });

    }
});
+4
source

Source: https://habr.com/ru/post/1621626/


All Articles