Need of optimized code for hide and show div in jQuery
Posted
by novellino
on Stack Overflow
See other posts from Stack Overflow
or by novellino
Published on 2010-05-03T14:44:23Z
Indexed on
2010/05/03
14:48 UTC
Read the original article
Hit count: 206
jQuery
Hello, I have a div:
<div id="p1" class="img-projects" style="margin-left:0;">
<a href="project1.php"> <img src="image1.png"/></a>
<div id="p1" class="project-title">Bar Crawler</div>
</div>
On mouse-over I want to add an image with opacity and make the project-title shown. So I use this code:
<script type="text/javascript">
$(function() {
$('.project-title').hide();
$('#p1.img-projects img').mouseover(
function() {
$(this).stop().animate({ opacity: 0.3 }, 800);
$('#p1.project-title').fadeIn(500);
});
$('#p1.img-projects img').mouseout(
function() {
$(this).stop().animate({ opacity: 1.0 }, 800);
$('#p1.project-title').fadeOut();
});
$('#p2.img-projects img').mouseover(
function() {
$(this).stop().animate({ opacity: 0.3 }, 800);
$('#p2.project-title').fadeIn(500);
});
$('#p2.img-projects img').mouseout(
function() {
$(this).stop().animate({ opacity: 1.0 }, 800);
$('#p2.project-title').fadeOut();
});
});
</script>
The code works fine but does anyone know a way to optimize my code?
Thank you
© Stack Overflow or respective owner