所以我想把它简化成一个函数,但我不知道怎么做。看来我应该能够从点击 id 中提取变量,然后在隐藏的 id 选择器中使用它。
$(document).ready(function(){
$(".hidden").animate({opacity:'0'});
$("#click1").click(function(){
$(".hidden").animate({opacity:'0'});
$("#hidden1").animate({opacity:'0'});
$("#hidden1").animate({opacity:'1'},"slow");
$("#hidden1").stop();
});
$("#click2").click(function(){
$(".hidden").animate({opacity:'0'});
$("#hidden2").animate({opacity:'0'});
$("#hidden2").animate({opacity:'1'},"slow");
$("#hidden2").stop();
});
$("#click3").click(function(){
$(".hidden").animate({opacity:'0'});
$("#hidden3").animate({opacity:'0'});
$("#hidden3").animate({opacity:'1'},"slow");
$("#hidden3").stop();
});
$("#click4").click(function(){
$(".hidden").animate({opacity:'0'});
$("#hidden4").animate({opacity:'0'});
$("#hidden4").animate({opacity:'1'},"slow");
$("#hidden4").stop();
});
});
<p id="click1">hover</p>
<p id="click2">hover</p>
<p id="click3">hover</p>
<p id="click4">hover</p>
<p id="hidden1" class="hidden">hidden 1</p>
<p id="hidden2" class="hidden">hidden 2</p>
<p id="hidden3" class="hidden">hidden 3</p>
<p id="hidden4" class="hidden">hidden 4</p>