简体   繁体   English

仅当屏幕大于 767 时才运行脚本

[英]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我只希望我的脚本在屏幕大于 767px 时运行,所以我用

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我只希望我的脚本在屏幕大于 767px 时运行

you need to check the window size after the click event!您需要在click事件后检查window 大小

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

Try replacing "$" with "jQuery".尝试用“jQuery”替换“$”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM