当我单击.typeform
元素时,我试图将动画应用于.nexto
元素。使用toggleClass
时,所有.typeform
都受到toggleClass
的影响。
单击.typeform
时,需要将动画应用于下一个.nexto
元素。请帮我。谢谢。
$('.nexto').on('click', function(event) {
$('.typeform-element').toggleClass('animations');
})
.animations {
animation: animation-1 1s linear;
}
@keyframes animation-1 {
0% {
top: -50px;
opacity: 0;
}
50% {
top: -25px;
opacity: 0.5;
}
100% {
top: 0px;
opacity: 1;
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="typeform">
<div class="typeform-element" id="fname">
<p><span class="list">1</span>→What's your First Name? *</p>
<input type="text" name="fname" placeholder="Type your answer..." autofocus>
<div class="ok-btn">
<a href="#lname" class="nexto">OK ✔</a>
</div>
</div>
<div class="typeform-element" id="lname">
<p><span class="list">2</span>→What's Your Last Name? *</p>
<input type="text" name="lname" placeholder="Type your answer...">
<div class="ok-btn">
<a href="#email" class="nexto">OK ✔</a>
</div>
</div>
<div class="typeform-element" id="email">
<p><span class="list">3</span>→Let's know your Email Address*</p>
<input type="email" name="email" placeholder="Type your answer...">
<div class="ok-btn">
<a href="#submit" class="nexto">OK ✔</a>
</div>
</div>
<div class="typeform-element" id="submit">
<div class="ok-btn">
<a href="#fname">Submit ✔</a>
</div>
</div>
</div>
答案 0 :(得分:3)
您需要访问父按钮,然后选择紧随其后的同级按钮,并仅切换其班级。
$('.nexto').on('click', function(event){
$(this).closest('.typeform-element').next('.typeform-element').toggleClass('animations');
});