我想淡出所有的div淡出事件工作,但當我的鼠標進入第一個div時,它會影響所有其他div。如果我沒有單獨定義demo和demo1函數,那麼它的工作正常否則它的工作是這樣的。我不明白什麼是錯的?Fadein,fadeout事件一起使用jquery
<html>
<head>
<title></title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
</head>
<body>
<p>Fade Out Example</p><br>
<div class="fade" id="div1" style="background-color:red;width:100px; height:100px"> </div><br>
<div class="fade" id="div2" style="background-color:blue;width:100px; height:100px"> </div><br>
<div class="fade" id="div3" style="background-color:cyan;width:100px; height:100px"> </div>
</body>
<script>
$(document).ready(function(){
$("#div1").bind("mouseenter",(demo));
$("#div1").bind("mouseleave",(demo1));
$("#div2").bind("mouseenter",(demo));
$("#div2").bind("mouseleave",(demo1));
$("#div3").bind("mouseenter",(demo));
$("#div3").bind("mouseleave",(demo1));
});
function demo()
{
$("#div1").css("background-color","lightgreen").fadeOut();
$("#div2").fadeOut();
$("#div3").fadeOut();
}
function demo1(){
$("#div1").css("background-color","red").fadeIn();
$("#div2").fadeIn();
$("#div3").fadeIn();
}
</script>
</html>
HTML裏面''運行它..真的嗎? :) –
這是錯誤,而張貼... :( –
你的代碼說淡出所有3或全部褪色3.如果那不是你想要的,那麼不要把它 –