jquery - 在媒体查询中创建 jquery 规则,有可能吗?
问题描述
我在 jquery 中创建事件时遇到问题。我的代码是这样的:
在 THML 中没有问题,因为它引用了一个事件。我在 jquery 中附加了代码:
$("nav ul li a").click(function(e) {
e.preventDefault();
var target = $(this).attr("href");
$("html,body").animate({
scrollTop: $(target).offset().top
},2000,"easeOutQuint");
});
这样,当我单击导航条目时,它会将我带到所需的元素......这里没有问题。
然后我创建了一个允许我全屏查看导航的hamb,它安静地打开和关闭,这是代码。
$("#hamb").click(function(e) {
if( $(this).hasClass("on") ){
$(this).removeClass("on");
$("#full").stop().fadeIn(800);
$("#full ul li").addClass("down");
$(this).css("z-index", "20");
$("#hamb span:nth-of-type(1)").addClass("ruota1");
$("#hamb span:nth-of-type(2)").css("opacity", "0");
$("#hamb span:nth-of-type(3)").addClass("ruota3");
} else {
$(this).addClass("on");
$("#full").stop().fadeOut(300);
$("#full ul li").removeClass("down");
$(this).css("z-index", "10");
$("#hamb span:nth-of-type(1)").removeClass("ruota1");
$("#hamb span:nth-of-type(2)").css("opacity", "1");
$("#hamb span:nth-of-type(3)").removeClass("ruota3");
}
});
我想确保当我点击一个声音时,导航会关闭。我已经尝试过这样做(#full 是导航):
$("nav ul li a").click(function(e) {
e.preventDefault();
var target = $(this).attr("href");
$("html,body").animate({scrollTop: $(target).offset().top},2000,"easeOutQuint");
$("#full").stop().fadeOut(800);
});
它有效,它悄悄地消失了..问题是导航在经典的水平版本中也消失了..我怎样才能确保这个规则只存在于窗口的某个宽度?所以你只使用平板电脑和手机?我试过:
if ($(window).width() < 960) {
example....
}
但是我不能很好地使用这个规则..我不能,有人可以帮助我吗?
解决方案
推荐阅读
- sql-server - 如何在 Sql Server 2014 中禁用身份缓存
- ruby - 这个递归函数置换生成器是如何工作的?
- reactjs - ReactJS - 无法使用 useCallback 重定向到页面
- apache-nifi - Nifi站点到站点
- javascript - Symfony - 集合表单原型不采用 html 类属性
- unity3d - 在 Canvas 上使用物理实例化对象
- linux - 为什么没有 atomic_add_and_test?
- arrays - 更改单输入代码以在反应中动态添加更多具有相同功能的输入字段
- regex - 在冒号之后但在下划线之前匹配正则表达式
- node.js - Joi 验证模式