我有这两个函数在鼠标悬停时选择我的标签,第一个用于左侧:
$(function() {
var $items = $('#vtab>ul>li' || '#vtab2>ul>li');
$items.mouseover(function() {
$items.removeClass('selected');
$(this).addClass('selected');
var index = $items.index($(this));
$('#vtab>div' && '#vtab2>div').hide().eq(index).show();
}).eq(0).mouseover();
});
这是右边的那个:
$(function() {
var $items = $('#vtab2>ul>li');
$items.mouseover(function() {
$items.removeClass('selected');
$(this).addClass('selected');
var index = $items.index($(this));
$('#vtab2>div').hide().eq(index).show();
}).eq(0).mouseover();
});
然后我有另一个淡入淡出页面的函数:
$(document).ready(function(){ $(“body”)。css(“display”,“none”);
$("body").fadeIn(3000);
$("a.transition").click(function(event){
event.preventDefault();
linkLocation = this.href;
$("body").fadeOut(2000, redirectPage);
});
function redirectPage() {
window.location = linkLocation;
}
});
由于某种原因,第二个功能仅在页面淡入时才起作用,一旦动画完成,它就会停止工作。如果我使屏幕足够小以至于我无法同时看到两个垂直列表,则第二个功能也有效。
有谁知道为什么会这样?我是jQuery的新手,我真的不知道从哪里开始。
答案 0 :(得分:0)
我相信你的问题是错误地使用javascript的布尔运算符。 $('#vtab> ul> li'||'#vtab2> ul> li');
相当于: $( '#vtab> UL>李')
因为'#vtab> ul> li'的广义布尔值为true且“||”是javascript“或”运算符和“或”短路上的第一个真实它找到。
一些相关的事实:
true || true || true == true
false || true || false == false
false || 'hey there' || true == 'hey there'
'hey there' || true == 'hey there'
'hey there' && true == true
true && 'hey there' == 'hey there'