Create a page with different elements and animations. Using different events, manipulate the classes and fade elements as well as animation and slide in/out with jQuery.
Create an accordion (see jquery-04 / accordion)
Below is the html Solution with output screenshot
Code : index.html
<!DOCTYPE html>
<html>
<head>
<!-- include jquery cdn file -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css" />
<link rel="stylesheet" href="/resources/demos/style.css" />
<!-- giving a title to our page -->
<title>jquery Demo</title>
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<!-- inserting all the script here in the script tag -->
<script>
$(document).ready(function () {
$("#btn1").click(function () {
$("#box").animate({ height: "300px" });
});
$("#btn2").click(function () {
$("#box").animate({ height: "100px" });
});
$("#flip").click(function () {
$("#panel").slideToggle("slow");
});
$("#fadein").click(function () {
$("#div1").fadeIn();
$("#div2").fadeIn("slow");
$("#div3").fadeIn(3000);
});
$(function () {
$("#accordion").accordion();
});
});
</script>
<!-- using css here in style tag -->
<style>
#panel,
#flip {
padding: 5px;
text-align: center;
background-color: #e5eecc;
border: solid 1px #c3c3c3;
}
#panel {
padding: 50px;
display: none;
}
</style>
</head>
<body>
<!-- animate section -->
<p>Demonstrate jquery animate function</p>
<button id="btn1">Animate height</button>
<button id="btn2">Reset height</button>
<div id="box" style="background: #98bf21; height: 100px; width: 100px; margin: 6px;"></div>
<!-- toogle section -->
<p>Demonstrate jquery slidetoggle function</p>
<div id="flip">Click to slide the panel down or up</div>
<div id="panel">Hello world!</div>
<!-- accordion section -->
<p>Demonstrate Accordion using jquery</p>
<div id="accordion">
<h3>Section 1</h3>
<div>
<p>
Mauris mauris ante, blandit et, ultrices a, suscipit eget, quam. Integer
ut neque. Vivamus nisi metus, molestie vel, gravida in, condimentum sit
amet, nunc. Nam a nibh. Donec suscipit eros. Nam mi. Proin viverra leo ut
odio. Curabitur malesuada. Vestibulum a velit eu ante scelerisque vulputate.
</p>
</div>
<h3>Section 2</h3>
<div>
<p>
Sed non urna. Donec et ante. Phasellus eu ligula. Vestibulum sit amet
purus. Vivamus hendrerit, dolor at aliquet laoreet, mauris turpis porttitor
velit, faucibus interdum tellus libero ac justo. Vivamus non quam. In
suscipit faucibus urna.
</p>
</div>
<h3>Section 3</h3>
<div>
<p>
Nam enim risus, molestie et, porta ac, aliquam ac, risus. Quisque lobortis.
Phasellus pellentesque purus in massa. Aenean in pede. Phasellus ac libero
ac tellus pellentesque semper. Sed ac felis. Sed commodo, magna quis
lacinia ornare, quam ante aliquam nisi, eu iaculis leo purus venenatis dui.
</p>
<ul>
<li>List item one</li>
<li>List item two</li>
<li>List item three</li>
</ul>
</div>
<h3>Section 4</h3>
<div>
<p>
Cras dictum. Pellentesque habitant morbi tristique senectus et netus
et malesuada fames ac turpis egestas. Vestibulum ante ipsum primis in
faucibus orci luctus et ultrices posuere cubilia Curae; Aenean lacinia
mauris vel est.
</p>
<p>
Suspendisse eu nisl. Nullam ut libero. Integer dignissim consequat lectus.
Class aptent taciti sociosqu ad litora torquent per conubia nostra, per
inceptos himenaeos.
</p>
</div>
</div>
<!-- fade section -->
<div id="fade-div">
<p>Demonstrate fadeIn() with different parameters.</p>
<button id="fadein">Click to fade in boxes</button><br />
<br />
<div id="div1" style="width: 80px; height: 80px; display: none; background-color: red;"></div>
<br />
<div id="div2" style="width: 80px; height: 80px; display: none; background-color: green;"></div>
<br />
<div id="div3" style="width: 80px; height: 80px; display: none; background-color: blue;"></div>
</div>
</body>
</html>
Output :
Get Answers For Free
Most questions answered within 1 hours.