这个代码出了什么问题?(Jquery)

What is wrong with this code? (Jquery)

本文关键字:Jquery 问题 什么 代码      更新时间:2023-09-26

这可能是一个愚蠢的错误,但我的大脑今天不工作了。

我有一个按钮和两个<h1>元素。当你按下按钮时,它们会产生动画,我希望当你悬停在文本上时,它会逐渐消失。

此外,当你按下按钮时,它会隐藏起来。

这是我的代码:

$(document).ready(function(){
    $("#button1").click(function() {
        $('#text1').animate({right: '700px'}, 'slow');
        $('#text2').animate({right: '900px'}, 'slow');
        $(this).toggle();
    });
    $('#text1', '#text2').mouseover(function(){
        $('#text1', '#text2').fadeTo('slow', 0);
    });
});

只是选择器。

$('#text1, #text2').mouseover(function(){
    $('#text1, #text2').fadeTo('slow', 0);
});

$('#text1', '#text2')实际上使用了$( selector [, context ] )形式——这里有解释——这意味着#text1必须在#text2内部。这可能不是你想要的。