日期:2014-05-16  浏览次数:20405 次

图片怎么向上位移
想实现点击图片之后,图片能够向上位移,要怎么实现呢?
图片

------解决方案--------------------
$('img').click(function() {
    $(this).animate({'top':'+=5px'});
});
------解决方案--------------------

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>test.html</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<script>
$(function(){
$('#imgs').click(function() {
    $(this).animate({'top':'-=10px'});//向上移动10px
}); 
})
</script>
</head>
<body>
<img src="top.jpg" id="imgs" style="position:absolute;top:100px;"/>
</body>
</html>


------解决方案--------------------
引用:
Quote: 引用:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>test.html</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<script>
$(function(){
$('#imgs').click(function() {
    $(this).animate({'top':'-=10px'});//向上移动10px
}); 
})
</script>
</head>
<body>
<img src="top.jpg" id="imgs" style="position:absolute;top:100px;"/>
</body>
</html>



$什么的是什么意思啊?今天第一次用JS写东西。

是jquery的写法,jquery是js的一个库,学会它的语法,你可以很轻便地写出复杂功能的js,包括可以模拟动画效果