【发布时间】:2014-10-15 19:52:09
【问题描述】:
所以这是我的问题,我正在为使用 jquery 的网站制作悬停效果的移动样式。尽管我一直在将希望受移动样式影响的元素放入变量中。虽然我的代码在我这样做时不起作用。我不太确定我做错了什么,但这是我的 jquery 脚本的 sn-p 以了解我正在尝试做什么:
$(function ($) {
var slidebar = new $.slidebars({siteClose:true, scrollLock:true}),
ua = navigator.userAgent,
navslide1 = $('nav.slide ul li:nth-child(1) a.mobile-nav-hover');
// I'm trying to create a variable for nav.slide that works. --%>
if (/iPod|iPad|iPhone|Android/.test(ua)) {
$('nav.slide ul li a').removeClass('hover').addClass('mobile-nav-hover');
// This is where I'm having problems. If I use the variable this code won't work. --!>
navslide1.on('touchstart click', function(){
navslide1.css({
"background-color":"#ffffff",
"color":"#000000"
});
}).on('touchend click', function(){
setTimeout(function(){
navslide1.css({
"background-color":"transparent",
"color":"#ffffff"
});
}, 120);
});
}
});
如果有人可以帮助我找出问题所在,那就太好了!
注意: 当我运行这段代码时,控制台中没有弹出错误,但是如果我使用 navslide1 变量,代码 sn -p 将无法工作。
【问题讨论】:
-
您应该解释到底出了什么问题。控制台中是否有错误? 任何事情会发生吗?如果有,是什么?
-
在我回答该问题的帖子中添加了一条注释。
标签: javascript jquery css nav