javascript - How to re-blink a div using css? -


this question has answer here:

i know can use below css blink div number of times specified:

html:

<div class="blink">blinking text</div> 

css:

@-webkit-keyframes blinker { 0% { opacity: 1.0; } 50% { opacity: 0.0; } 100% { opacity: 1.0; } } @-moz-keyframes blinker { 0% { opacity: 1.0; } 50% { opacity: 0.0; } 100% { opacity: 1.0; } } .blink { -webkit-animation: blinker 1s 5; -moz-animation: blinker 1s 5; animation: blinker 1s 5; } 

by using css way, div blink after page loaded without calling js function. if want re-blink div after user press button? there's no function call on "onclick".

<button onclick="">blink again!</button> 

any idea how it?

jsfiddle

you need remove class 'blink' add again, in order restart css animation

you'll need use settimeout doesn't have class added before has has class taken away it

$("#blinkagain").click(function() {      var $el = $(".blink");      $el.removeclass("blink");      settimeout(function() {$el.addclass("blink");}, 500);  });
@-webkit-keyframes blinker {    0% {      opacity: 1.0;    }    50% {      opacity: 0.0;    }    100% {      opacity: 1.0;    }  }  @-moz-keyframes blinker {    0% {      opacity: 1.0;    }    50% {      opacity: 0.0;    }    100% {      opacity: 1.0;    }  }  .blink {    -webkit-animation: blinker 1s 5;    -moz-animation: blinker 1s 5;    animation: blinker 1s 5;  }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <div class="blink">blinking text</div>  <button id="blinkagain">blink again!</button>


Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -