简体   繁体   English

jQuery鼠标悬停和淡入功能

[英]Jquery mouseover and fade in functions

I have these two functions that select tabs of mine on mouseover, the first one is for the left side: 我有以下两个功能可以在鼠标悬停时选择我的标签,第一个用于左侧:

$(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();
    });

This one's for the right side: 这个是右边的:

 $(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();
    });

and then I have another function that fades the page in and out: 然后我还有另一个功能可以使页面淡入淡出:

$(document).ready(function() { $("body").css("display", "none"); $(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;
}

}); });

For some reason the second function only works WHILE the page is fading in, it stops working once the animation is done. 由于某种原因,第二个功能仅在页面淡入时才起作用,动画完成后它将停止工作。 The second function also works if I make the screen small enough that I can't see both of my vertical lists at the same time. 如果我将屏幕缩小得足够小以致于无法同时看到两个垂直列表,则第二个功能也可以使用。

Does anyone know why this may be? 有谁知道为什么会这样吗? I'm new to jQuery and I really don't know where to begin. 我是jQuery的新手,我真的不知道从哪里开始。

I believe your issue is incorrectly using javascript's boolean operators. 我相信您的问题是使用JavaScript的布尔运算符错误地引起的。 $('#vtab>ul>li' || '#vtab2>ul>li'); $('#vtab> ul> li'||'#vtab2> ul> li');

Is equivalent to: $('#vtab>ul>li') 等效于:$('#vtab> ul> li')

Because the generalized boolean of '#vtab>ul>li' is true and "||" 因为'#vtab> ul> li'的广义布尔值为true,所以“ ||” is the javascript "or" operator and "or" short circuits on the first true it finds. 是找到的第一个真值的javascript“或”运算符和“或”短路。

Some relevant truths: 一些相关的事实:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM