Reputation: 190
i want that my image in that animate to top and this is the code. what is the problem
<!DOCTYPE HTML>
<html>
<head>
<title>Majid</title>
<style>
* {
margin: 0 auto;
padding: 0;
}
body {
background: #333;
}
#box {
width: 391px;
height: 131px;
margin-top: 300px;
background: #555;
position: relative;
}
.icon {
width: 128px;
height: 128px;
float: left;
border-1px solid #fff;
margin: 1px;
}
</style>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript">
function icons(){
$("a img").animate({ top: '128px' }, 300);
}
</script>
</head>
<body>
<div id="box">
<a href="JavaScript:();" onclick="icons();" class="icon"><img src="images/fb.jpg" alt="" /></a>
<a href="JavaScript:();" onclick="icons();" class="icon"><img src="images/tt.jpg" alt="" /></a>
<a href="JavaScript:();" onclick="icons();" class="icon"><img src="images/gp.jpg" alt="" /></a>
</div>
</body>
</html>
Upvotes: 0
Views: 105
Reputation: 842
$("#box a").click(function(event) {
event.preventDefault();
$(this).find("img").stop().animate ({"top" : '128px'} , 300);
});
and addd in css
.icon img{position:relative;}
seee working demo
Upvotes: 1
Reputation: 15393
$(function() {
$("#box a").click(function(event) {
event.preventDefault();
$(this).find("img").stop().animate ({"top" : '128px'} , 300);
});
});
Try this:
<!DOCTYPE HTML>
<html>
<head>
<title>Majid</title>
<style>
* {margin:0 auto; padding:0;}
body {background:#333;}
#box {width:391px; height:131px; margin-top:300px; background:#555; position:relative;}
.icon {width:128px; height:128px; float:left; border-1px solid #fff; margin:1px;}
</style>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript">
$(function() {
$("#box a").click(function(event) {
event.preventDefault();
$(this).find("img").stop().animate ({"top" : '128px'} , 300);
});
});
</script>
</head>
<body>
<div id="box">
<a href="#" class="icon"><img src="images/fb.jpg" alt="" /></a>
<a href="#" class="icon"><img src="images/tt.jpg" alt="" /></a>
<a href="#" class="icon"><img src="images/gp.jpg" alt="" /></a>
</div>
</body>
</html>
Upvotes: 0