2014-05-07 51 views
0

我希望我的圖像在這個動畫頂部,這是代碼。這是什麼問題使用jquery動畫圖像頂部

<!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> 
+0

甲酸代碼PLZ –

+0

ü可以使小提琴? –

回答

1

只需添加以下代碼到你的CSS

.icon img{position:relative;} 
0
$(function() { 

    $("#box a").click(function(event) { 

    event.preventDefault(); 
    $(this).find("img").stop().animate ({"top" : '128px'} , 300); 

    }); 

}); 

試試這個:

<!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> 
1
$("#box a").click(function(event) { 

    event.preventDefault(); 
    $(this).find("img").stop().animate ({"top" : '128px'} , 300); 

    }); 

,並在CSS ADDD

.icon img{position:relative;} 

SEEE工作演示

http://jsfiddle.net/eyP4N/1/