[英]Run script only if screen is greater than 767
我只希望我的腳本在屏幕大於 767px 時運行,所以我用
if($(window).width() > 767){
}
這是我當前的腳本:
if($(window).width() > 767){
$('header input').click(function() {
$('#holiday-bg').css({
'background-position': 'center center',
'padding-bottom': '39%',
});
});
}
該腳本在未包裝時有效,有什么想法嗎?
我只希望我的腳本在屏幕大於 767px 時運行
您需要在click
事件后檢查window 大小!
$( 'header input' ).click(function() {
if( $( window ).width() > 767 )
{
$( '#holiday-bg' ).css({
'background-position': 'center center',
'padding-bottom': '39%',
});
}
});
嘗試用“jQuery”替換“$”。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.