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?
Asked
Active
Viewed 6,804 times
3
-
1Also consider css animations! – biziclop Jun 26 '12 at 17:58
-
I'm not sure if I can use CSS, since the animation must be stopped in response to a button. – danieljmt Jun 26 '12 at 17:59
-
setup a demo fiddle. (http://jsbin.com) Show us how your HTML / CSS looks like. – Roko C. Buljan Jun 26 '12 at 18:00
-
@DanielMarshall you can always remove the animation from css when button clicked – Huangism Jun 26 '12 at 18:00
-
@Roko C. Bulja http://jsbin.com/akewiz/2/edit#javascript,html – danieljmt Jun 26 '12 at 18:04
-
Click the img: http://jsfiddle.net/37Esn/2/ – biziclop Jun 26 '12 at 18:06
-
http://stackoverflow.com/questions/6422790/css-create-white-glow-around-image – zod Jun 26 '12 at 18:13
1 Answers
4
html:
<button id="stop">STOP IT!</button>
<div class="images">
<img src="img1.jpg" />
<img src="img2.jpg" class="glowed"/>
</div>
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.

Roko C. Buljan
- 196,159
- 39
- 305
- 313