当屏幕宽度大于480时禁用jquery功能

编程入门 行业动态 更新时间:2024-10-26 22:28:14
本文介绍了当屏幕宽度大于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功能

本文发布于:2023-11-15 16:50:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1596232.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:宽度   屏幕   功能   jquery

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!