How Can You Use Jquery To Animate A Flash To A Button
How to make an element "flash" in jQuery ?
In this article, we will create flashing elements using jQuery. There are two approaches that are discussed below.
We will use the CDN link to include jQuery content. The CDN link of jQuery must be added to the HTML document.
https://code.jquery.com/
We will use HTML5 and CSS3 to create the structure of our certificate and add the required elements.
- HTML Lawmaking: We volition add together some dummy text inside a div element with black edge. Subsequently, we will make this text flash.
<!DOCTYPE html>
<
html
lang
=
"en"
>
<
caput
>
<
meta
charset
=
"UTF-8"
>
<
meta
name
=
"viewport"
content="
width
=
device
-width,
initial-scale
=
1
.0">
<
championship
>Certificate</
championship
>
<
link
rel
=
"stylesheet"
href
=
"mode.css"
>
<
script
src
=
integrity
=
"sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
crossorigin
=
"anonymous"
>
</
script
>
</
caput
>
<
trunk
>
<
h2
form
=
"header"
>Geeks for Geeks</
h2
>
<
div
class
=
"element"
>
<
p
grade
=
"text flash1"
>
This is the flashing element</
p
>
</
div
>
</
body
>
</
html
>
- CSS Lawmaking: Let u.s. design the elements using CSS to make the page bonny.
CSS code:
<style>
.header {
margin-left
:
18px
;
color
:
rgb
(
0
,
153
,
0
);
}
.chemical element {
border
:
2px
solid
black
;
width
:
12
vw;
padding
:
5px
;
}
</style>
- Output:
Approach 1: Using fadeIn() and fadeOut() Method: In this approach, nosotros will set consecutive fadeIn() and fadeOut() methods on the element and then set an interval to ensure the flashing continues indefinitely.
$(certificate).ready(() => {
setInterval(() => {
$(
'p'
).fadeIn();
$(
'p'
).fadeOut();
}, 500);
});
Example:
<!DOCTYPE html>
<
html
lang
=
"en"
>
<
caput
>
<
meta
charset
=
"UTF-viii"
>
<
meta
name
=
"viewport"
content="
width
=
device
-width,
initial-scale
=
1
.0">
<
title
>
How to make an element
"wink" in jQuery?
</
title
>
<
script
src
=
integrity
=
"sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
crossorigin
=
"anonymous"
>
</
script
>
<
manner
>
.header {
margin-left: 18px;
color: rgb(0, 153, 0);
}
.element {
border: 2px solid black;
width: 12vw;
padding: 5px;
}
</
manner
>
</
caput
>
<
body
>
<
h2
class
=
"header"
>Geeks for Geeks</
h2
>
<
div
class
=
"chemical element"
>
<
p
course
=
"text flash1"
>
This is the flashing chemical element
</
p
>
</
div
>
<
script
>
$(document).ready(() => {
const lheight = $('.chemical element').height();
setInterval(() => {
$('p').fadeIn();
$('p').fadeOut();
// The post-obit lawmaking keeps the
// height of the div intact
if ($('.element').height() !== 0) {
$('.element').css('height', `${lheight}px`);
}
}, 500);
});
</
script
>
</
torso
>
</
html
>
Output:
Approach 2: Using toggleClass() method: We volition use the method to change CSS classes with different designs. Every bit a result, the element will seem to be flash.
Let us add the required CSS classes:
<
style
>
.header {
colour: rgb(0, 153, 0);
}
.chemical element {
edge: 2px solid black;
width: 12vw;
padding: 5px;
}
.flash1 {
color: black;
}
.flash2 {
color: rgb(0, 153, 0);
}
</
fashion
>
The following JavaScript will help us to make the text element flash with a different color:
$(certificate).ready(() => {
setInterval(() => {
switch
($(
"p"
).attr(
"class"
)) {
case
"text flash1"
:
$(
"p"
).toggleClass(
"flash1 flash2"
);
break
;
case
"text flash2"
:
$(
"p"
).toggleClass(
"flash2 flash1"
);
}
}, 500);
});
Instance:
<!DOCTYPE html>
<
html
lang
=
"en"
>
<
head
>
<
meta
charset
=
"UTF-viii"
>
<
meta
name
=
"viewport"
content
=
"width=device-width,initial-scale=one.0"
>
<
script
src
=
integrity
=
"sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
crossorigin
=
"anonymous"
>
</
script
>
<
title
>
How to make an element
"wink" in jQuery?
</
championship
>
<
manner
>
.header {
margin-left: 16px;
color: rgb(0, 153, 0);
}
.element {
edge: 2px solid black;
width: 12vw;
padding: 5px;
}
.flash1 {
color: black;
}
.flash2 {
colour: rgb(0, 153, 0);
}
</
style
>
</
caput
>
<
body
>
<
h2
course
=
"header"
>Geeks for Geeks</
h2
>
<
div
grade
=
"chemical element"
>
<
p
class
=
"text flash1"
>
This is the flashing element
</
p
>
</
div
>
<
script
>
$(document).ready(() => {
setInterval(() => {
switch ($("p").attr("class")) {
case "text flash1":
$("p").toggleClass("flash1 flash2");
break;
case "text flash2":
$("p").toggleClass("flash2 flash1");
}
}, 500);
});
</
script
>
</
body
>
</
html
>
Output:
Source: https://www.geeksforgeeks.org/how-to-make-an-element-flash-in-jquery/
Posted by: mcnamaragulay1979.blogspot.com
0 Response to "How Can You Use Jquery To Animate A Flash To A Button"
Post a Comment