DW中如何使图片随滚动条运动而运动(滚动条往下拉,图片也往下)?图片是有链接的,麻烦请具体解析一下。
2013-07-17
展开全部
要用JS来做。<html>
<head>
<script language="javascript">
function moveImage(){
document.getElementById("div1").style.left = 0;
document.getElementById("div1").style.top = document.body.scrollTop;
}
var t1 = window.setInterval("moveImage()",100);
</script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>图片位移</title>
</head>
<body bgcolor="#CCCC00">
<div id="div1" style="position:absolute"><a href="你的链接"> <img src="images/hair.png" id="image1" /></a></div><!--这个地址改成你自己的图片-->
</body>
</html>
上面的是你的要求。下面是一个小例子。可以实现图片在页面上滚动。JS代码如下:
<script language="javascript">
var left = 0;
var top = 0;
function moveImage(){
if(left > (document.body.clientWidth)-(document.getElementById("div1").offsetWidth)-4){
left = -left;
}
if(top > (document.body.clientHeight)-(document.getElementById("div1").offsetHeight)-4){
top = -top;
}
left += 4;
top += 4;
document.getElementById("div1").style.left = Math.abs(left);
document.getElementById("div1").style.top = Math.abs(top);
}
var t1 = window.setInterval("moveImage()",100);
</script>
<head>
<script language="javascript">
function moveImage(){
document.getElementById("div1").style.left = 0;
document.getElementById("div1").style.top = document.body.scrollTop;
}
var t1 = window.setInterval("moveImage()",100);
</script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>图片位移</title>
</head>
<body bgcolor="#CCCC00">
<div id="div1" style="position:absolute"><a href="你的链接"> <img src="images/hair.png" id="image1" /></a></div><!--这个地址改成你自己的图片-->
</body>
</html>
上面的是你的要求。下面是一个小例子。可以实现图片在页面上滚动。JS代码如下:
<script language="javascript">
var left = 0;
var top = 0;
function moveImage(){
if(left > (document.body.clientWidth)-(document.getElementById("div1").offsetWidth)-4){
left = -left;
}
if(top > (document.body.clientHeight)-(document.getElementById("div1").offsetHeight)-4){
top = -top;
}
left += 4;
top += 4;
document.getElementById("div1").style.left = Math.abs(left);
document.getElementById("div1").style.top = Math.abs(top);
}
var t1 = window.setInterval("moveImage()",100);
</script>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询