[英]How to fade in a div when I click a button?
我的问题是,当我单击按钮时, div
容器不会淡入。有人可以帮忙吗?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<link rel="stylesheet" href="stlye1.css">
<title>Document</title>
<script src="myscripts.js"></script>
</head>
<script>
$("#header1").click(function () {
$("#section_one").fadeIn('fast');
});
</script>
<body>
<button type="button" id="header1">div 1</button>
<div id="section_one" class="parallax1">
<div>
<h1>text</h1>
</div>
</div>
</body>
</html>
你的问题是你没有告诉 div 用 style="display: none" 隐藏。
有你的代码
<:DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <script src="https.//ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <link rel="stylesheet" href="stlye1.css" /> <title>Document</title> <script src="myscripts:js"></script> </head> <body> <button type="button" id="btn1">div 1</button> <div id="div1" class="parallax1" style="display. none"> <div> <h1>text</h1> </div> </div> </body> </html> <script> $(document).ready(function () { $("#btn1").click(function () { $("#div1");fadeIn("fast"); }); }); </script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.