Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS/jQuery: make the icon blink

Tags:

jquery

css

I remember doing some css learning where i learned to make text-decoration: blink, and the text started blinking.

Now i have a icon,

.iconPM{
background: url(../images/icons/mail_16x16.png) no-repeat;
width: 16px;
height: 16px;
border: none;
display:inline-block;
}

Wonder if i can make this blink, either by simple css or jquery if required. Or maybe any other nice effects available in jquery recommended

like image 904
Karem Avatar asked Jan 11 '11 20:01

Karem


People also ask

How to blink a button using jQuery?

JavaScript Code :fadeOut(500); $('. blink'). fadeIn(500); } setInterval(blink_text, 1000); HTML.

How to add blink animation in jQuery?

When you want to add a blinking animation to an element in your web page, you can use the jQuery fading effects in combination with the JavaScript setInterval() method so that the element will blink once every one or two seconds.

How do you blink an icon in HTML?

You can add the . blink class to any HTML element to make it blink.

How to make text blink in jQuery?

Blink text using jQuery toggleClass() function In this example, we will use the toggleClass() function to toggle between the classes of the selected element, <h1> . This will helps us to produce a blinking effect.


3 Answers

A simple jquery like this would do it:

function blink(){
    $('.iconPM').delay(100).fadeTo(100,0.5).delay(100).fadeTo(100,1, blink);
}

$(document).ready(function() {
    blink();
});
like image 77
Hoatzin Avatar answered Oct 12 '22 12:10

Hoatzin


CSS animations are fairly well supported now, so I thought I'd share a CSS only answer.

.iconPM {
  background: url(https://raw.githubusercontent.com/stephenhutchings/typicons.font/493867748439a8e1ac3b92e275221f359577bd91/src/png-24px/mail.png) center no-repeat;
  background-size: 16px 16px;
  width: 16px;
  height: 16px;
  border: none;
  display:inline-block;
  
  animation: blink 2s ease-in infinite;
}

@keyframes blink {
  from, to { opacity: 1 }
  50% { opacity: 0 }
}
<span class="iconPM"></span>
like image 16
SeinopSys Avatar answered Oct 12 '22 11:10

SeinopSys


What about this?

CSS:

.iconPM.no-image{ background:none; }

JS:

var toggleClassFcn = function(){$(".iconPM").toggleClass("no-image");}
setInterval(toggleClassFcn, 300);

Just be careful as with any other animations on the page. It will consume thread on the page.

like image 3
Petr Kozelek Avatar answered Oct 12 '22 12:10

Petr Kozelek