我想制作一个简单的电子邮件输入 + 按钮表单,一旦提交,应该在同一页面上替换为另一个 div。我在表单上应用了 jquery 的 .hide("slow") ,在第二个 div 上应用了 .show("slow") ,虽然它确实显示/隐藏元素,但它不应用平滑过渡。
我究竟做错了什么??
实例: https: //codepen.io/mcancode/pen/vYKXmbr
代码:
<!DOCTYPE html>
<html>
<head>
<style>
#subscribed > div > p {
display: none;
}
</style>
</head>
<body>
<main>
<section id="newsletter">
<div id="unsubscribed">
<h3>Subscribe to our newsletter to get 10% off your next purchase</h3>
<form id="newsletter-form">
<div>
<input type="email" placeholder="Enter your email">
<button type="submit">
Submit
</button>
</div>
</form>
</div>
<div id="subscribed">
<div>
<p>Thank you for subscribing! You should receive an email with the discount code in the next 5 minutes.</p>
</div>
</div>
</section>
<!-----------------END OF NEWSLETTER---------->
</main>
<!--JS files...-->
<!-- jQuery and JS bundle w/ Popper.js -->
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script>
$(() => {
//check when newsletter form submitted
$("#newsletter-form").submit((event)=> {
event.preventDefault();
$("#unsubscribed").hide("slow");
$("#subscribed>div>p").show("slow");
})
});
</script>
</body>
</html>
弑天下
相关分类