[英]Jquery mouseover and fade in functions
我有以下兩個功能可以在鼠標懸停時選擇我的標簽,第一個用於左側:
$(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的新手,我真的不知道從哪里開始。
我相信您的問題是使用JavaScript的布爾運算符錯誤地引起的。 $('#vtab> ul> li'||'#vtab2> ul> li');
等效於:$('#vtab> ul> li')
因為'#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'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.