Recent Posts
- jQuery attrAugust 12, 2021
- jQuery mouseenterAugust 9, 2021
- jQuery ToggleclassAugust 6, 2021
- jQuery attr
Introduction to jQuery UI effect()
jQuery UI effect() method is used to apply an animation effect to any DOM element. jQuery UI offers this method to provide a large set of various animations to create visual effects making the UI look more appealing and interesting to the users.jQuery UI effect() method basically applies a named effect to any element where the name of the effect to be used is passed to the effect() method. A number of effects also support the show and hide mode which can be implemented using show(), hide(), and toggle() methods.
Syntax:
$(selector).effect(effectType[, options ] [, duration ] [, complete ]);
where,
How jQuery UI effect() Method Works?
jQuery UI effect() method works by applying a named animation effect to a selected element. This method manages a variety of animation effects to be applied to the selected elements to make web pages attractive and interactive.
Elements can be hidden, made visibly, shaken, made to bounce and many more such effects can be applied using this method.
Examples to Implement jQuery UI effect()
Let us look at some of the examples to understand the working of the jQuery UI effect() method.
Example #1
Let us consider a simple example to understand the functionality of the effect() method with the “bounce” effect type.
Code:
<!DOCTYPE html>
<head>
<title>jQuery UI Effect Example</title>
<link
href=”https://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css”
rel=”stylesheet”
/>
<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>
<script>
$(document).ready(function () {
$(“#box-div”).click(function () {
$(“#box-div “).effect(
“bounce”,
{
times: 5,
distance: 100,
},
2000,
function () {
$(this).css(“background”, “yellow”);
}
);
});
});
</script>
<style>
#box-div {
width: 350px;
height: 150px;
padding-top: 20px;
padding-left: 5px;
font-size: 24px;
text-align: center;
color: maroon;
background-color: cadetblue;
}
</style>
</head>
<body>
<center>
<b style=”font-size: 20px;”>jQuery UI Bounce Effect</b>
<br /><br />
<div id=”box-div”>
Click here to<br /><br /><b>see the Bounce effect</b>
</div>
</center>
</body>
</html>
Output:
Example #2
The following example illustrates the use of effect() method with the “shake” effect type.
Code:
<!DOCTYPE html>
<head>
<title>jQuery UI Effect Example</title>
<link
href=”https://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css”
rel=”stylesheet”
/>
<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>
<script>
$(document).ready(function () {
$(“#box-div”).click(function () {
$(“#box-div “).effect(
“shake”,
{
times: 5,
distance: 100,
},
2000,
function () {
$(this).css(“background”, “yellow”);
}
);
});
});
</script>
<style>
#box-div {
width: 350px;
height: 150px;
padding-top: 20px;
padding-left: 5px;
font-size: 24px;
text-align: center;
color: maroon;
background-color: cadetblue;
}
</style>
</head>
<body>
<center>
<b style=”font-size: 20px;”>jQuery UI Shake Effect</b>
<br /><br />
<div id=”box-div”>
Click here to<br /><br /><b>see the Shake effect</b>
</div>
</center>
</body>
</html>
Output:
Example #3
The following example illustrates the use of effect() method with the “explode” effect type.
Code:
<!DOCTYPE html>
<head>
<title>jQuery UI Effect Example</title>
<link
href=”https://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css”
rel=”stylesheet”
/>
<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>
<script>
$(document).ready(function () {
$(“#box-div”).click(function () {
$(“#box-div “).effect({
effect: “explode”,
easing: “easeInExpo”,
pieces: 9,
duration: 1500
});
});
});
</script>
<style>
#box-div {
width: 350px;
height: 150px;
padding-top: 20px;
padding-left: 5px;
text-align: center;
color: maroon;
background-color: cadetblue;
}
</style>
</head>
<body>
<center>
<b style=”font-size: 20px;”>jQuery UI Explode Effect</b>
<br /><br />
<div id=”box-div”>
Click here to<br /><br /><b>see the Explode effect</b>
</div>
</center>
</body>
</html>
Output:
Example #4
The following example illustrates the use of effect() method with the “fold” effect type.
Code:
<!DOCTYPE html>
<head>
<title>jQuery UI Effect Example</title>
<link
href=”https://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css”
rel=”stylesheet”
/>
<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>
<script>
$(document).ready(function () {
$(“#box-div”).click(function () {
$(“#box-div “).effect({
effect: “fold”,
easing: “easeInExpo”,
duration: 3000
});
});
});
</script>
<style>
#box-div {
width: 350px;
height: 150px;
padding-top: 20px;
padding-left: 5px;
font-size: 24px;
text-align: center;
color: maroon;
background-color: cadetblue;
}
</style>
</head>
<body>
<center>
<b style=”font-size: 20px;”>jQuery UI Fold Effect</b>
<br /><br />
<div id=”box-div”>
Click here to<br /><br /><b>see the Fold effect</b>
</div>
</center>
</body>
</html>
Output
Example #5
The following example illustrates the use of effect() method with the “highlight” effect type.
Code:
<!DOCTYPE html>
<head>
<title>jQuery UI Effect Example</title>
<link
href=”https://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css”
rel=”stylesheet”
/>
<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>
<script>
$(document).ready(function () {
$(“#box-div”).click(function () {
$(“#box-div “).effect({
effect: “highlight”,
duration: 3000
});
});
});
</script>
<style>
#box-div {
width: 350px;
height: 150px;
padding-top: 20px;
padding-left: 5px;
font-size: 24px;
text-align: center;
color: maroon;
background-color: cadetblue;
}
</style>
</head>
<body>
<center>
<b style=”font-size: 20px;”>jQuery UI Highlight Effect</b>
<br /><br />
<div id=”box-div”>
Click here to<br /><br /><b>see the Highlight effect</b>
</div>
</center>
</body>
</html>
Output:
Conclusion
MCP is the right place for best computer Courses institute and advance Courses in Mohali and Chandigarh.The Complete Programming Academy can change your life – providing you with the knowledge, skills, and performance in a second language which helps you to excel in your job.You can also Contact us for 6 month industrial training institute in Mohali.