当屏幕宽度大于480时禁用jquery功能 [英] Disable jquery function when screen width larger than 480
本文介绍了当屏幕宽度大于480时禁用jquery功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是新手(开玩笑吗?!),我无法使它正常工作.我在这里做错了什么? 如果屏幕宽度大于480,我不希望此功能执行任何操作,仅在屏幕宽度为480及以下时才触发.
I'm a newbie (no kidding?!) and I can't get this to work. What am I doing wrong here? If the screen width is larger than 480 I don't want this function to do anything, only to fire when screen width is 480 and below.
if ( screen.availWidth < 480 ) {
$(document).ready(function(){
$(".reklam").click(function(){
$('.reklam').attr('src','bilder/480/reklam_on.jpg');
});
});
}
推荐答案
由于屏幕大小可以更改(如果用户重新调整窗口大小),那么在事件中包含if语句是否更有意义?
Because screen size can change (if a user re-sizes the window), would it be more relevant to have the if statement within the event?
查看示例:
$(document).ready(function(){
$(".reklam").click(function(){
if ($(window).width() < 480) {
$('.reklam').attr('src','bilder/480/reklam_on.jpg');
}
});
});
这篇关于当屏幕宽度大于480时禁用jquery功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文