Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Glowing image with jQuery/Javascript

I have two images. One that is normal, and another that is more colourised. I want to have this image displaying on top of the other and having a "glowing" effect where it switches between transparent and opaque every second or so. I also need to stop this effect when the user presses a particular button. How would I go about doing this with jQuery or Javascript?

like image 537
danieljmt Avatar asked Apr 14 '26 04:04

danieljmt


1 Answers

jsBin demo

html:

<button id="stop">STOP IT!</button>

<div class="images">
     <img src="img1.jpg" />
     <img src="img2.jpg" class="glowed"/>
</div>

jquery:

var playing = true;

function loop(){
  if(playing){
    $('.images img:eq(1)').fadeIn(700, function(){
      $(this).fadeOut(700,loop);
    });
  }
}

loop(); // start loop


$('#stop').click(function(){
  playing=0;
}); 

Just position the two images absolute:

  .images img{
    position:absolute;
  }

  .glowed{
    box-shadow: 0px 0px 30px 2px #cf5
  }

I used css3 box shadow, but you could use a glowed .png image instead.

like image 100
Roko C. Buljan Avatar answered Apr 16 '26 18:04

Roko C. Buljan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!