简体   繁体   中英

Run script only if screen is greater than 767

I only want my script to run if the screen is greater than 767px, so I wrapped my script with

if($(window).width() > 767){
}

Here is my current script:

if($(window).width() > 767){
  $('header input').click(function() {
    $('#holiday-bg').css({
      'background-position': 'center center',
      'padding-bottom': '39%',
    });
  });
}

The script works when it is not wrapped, any ideas?

I only want my script to run if the screen is greater than 767px

you need to check the window size after the click event!

$( 'header input' ).click(function() {
    if( $( window ).width() > 767 )
    {
        $( '#holiday-bg' ).css({
           'background-position': 'center center',
           'padding-bottom': '39%',
        });
    }
});

Try replacing "$" with "jQuery".

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