【发布时间】:2021-09-09 00:23:02
【问题描述】:
#rock {
display: none;
position: relative;
left: 49.4%
}
#paper {
display: none;
position: relative;
left: 49%;
bottom: 81px;
}
#scissors {
display: none;
position: relative;
left: 48.14%;
bottom: 162px;
}
#shoot {
display: none;
position: relative;
left: 48.7%;
bottom: 243px;
}
我试图让这些 h2 元素在单击三个按钮之一后一个接一个地淡入然后淡出,但是我的 JQuery 不适用于淡入部分(我正在尝试使用这个因为我是 JavaScript 和 JQuery 的新手,所以我是零碎的)。这是我的脚本:
$(document).ready(function(){
$("button").click(function(){
$("#rock").fadeIn();
$("#paper").fadeIn();
$("#scissors").fadeIn("slow");
$("#shoot").fadeIn(3000);
});
});
<div class="selections">
<button class="selection" data-selection="rock">🗻</button>
<button class="selection" data-selection="paper">????</button>
<button class="selection" data-selection="scissors">✂</button>
</div>
<h2 class="chant" id="rock">Rock</h2>
<h2 class="chant" id="paper">Paper</h2>
<h2 class="chant" id=scissors>Scissors</h2>
<h2 class="chant" id="shoot">Shoot!</h2>
`
【问题讨论】:
-
您的代码应该已经正确淡入这些元素。请记住,要让淡入效果真正发挥作用,它必须被隐藏起来。
标签: javascript html jquery fadein fade