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?
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?
Share Improve this question asked Jun 26, 2012 at 17:57 danieljmtdanieljmt 371 silver badge6 bronze badges 7- 1 Also consider css animations! – biziclop Commented Jun 26, 2012 at 17:58
- I'm not sure if I can use CSS, since the animation must be stopped in response to a button. – danieljmt Commented Jun 26, 2012 at 17:59
- setup a demo fiddle. (jsbin.) Show us how your HTML / CSS looks like. – Roko C. Buljan Commented Jun 26, 2012 at 18:00
- @DanielMarshall you can always remove the animation from css when button clicked – Huangism Commented Jun 26, 2012 at 18:00
- @Roko C. Bulja jsbin./akewiz/2/edit#javascript,html – danieljmt Commented Jun 26, 2012 at 18:04
1 Answer
Reset to default 4jsBin 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.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745361270a4624370.html
评论列表(0条)