///pc/img/blank.gif" width="12" height="8">当前位置:///default.htm" class="under">亿度网络 -> ///pc/index.htm" class="under">网页制作教程 -> JavaScript
///pc/homepage/javascript/sample/img/bule.gif" width="207" height="13"> ///pc/homepage/javascript/sample/img/blank.gif" width="1" height="1"> ///pc/homepage/javascript/sample/img/js.gif" width="186" height="20"> ///pc/homepage/javascript/sample/img/blank.gif" width="1" height="1">
///pc/homepage/javascript/sample/img/blank.gif" width="1" height="1"> ///pc/homepage/javascript/sample/img/blank.gif" width="1" height="1">
    文字上下移动 ///pc/homepage/javascript/sample/img/blank.gif" width="1" height="1">  
    ///pc/homepage/javascript/sample/img/bule1.gif" width="28" height="49">  
效 果 演 示 ///pc/homepage/javascript/sample/img/bule2.gif" width="11" height="18">

    

     拖动图片试一试!

  ///pc/homepage/javascript/sample/img/draw.jpg" class="drag">

 

   
 
源代码如下 ///pc/homepage/javascript/sample/img/bule2.gif" width="11" height="18">



这段程序放在<body>与</body>之间

   
源程序讲解: ///pc/homepage/javascript/sample/img/bule2.gif" width="11" height="18">
  ///pc/homepage/javascript/sample/img/bule1.gif" width="28" height="49">  

<style>
<!--.drag{position:relative;cursor:hand} -->
</style>
定义一个样式。
<script language="JavaScript">
var dragapproved=false
var z,x,y
声明几个变量。
function move()
{ if (event.button==1&&dragapproved)
定义一个函数move(),判断鼠标是否是按下状态。
{ z.style.pixelLeft=temp1+event.clientX-x
z.style.pixelTop=temp2+event.clientY-y
return false }}
定义图片左上角的位置。
function drags()
{ if (!document.all)
return
定义一个函数drags()。如果是Netscape浏览器,就返回。所以此效果,在Netscape浏览器中看不到。
if (event.srcElement.className=="drag")
{ dragapproved=true
z=event.srcElement
temp1=z.style.pixelLeft
temp2=z.style.pixelTop
x=event.clientX
y=event.clientY
如果鼠标左键被按下,返回z,temp1,temp2,x,y的值。
document.onmousemove=move }}
document.onmousedown=drags
document.onmouseup=new
Function("dragapproved=false")
</script>
当鼠标移动时,执行move()函数,当鼠标按下的时候,执行drags函数,当鼠标抬起的时候,不执行任何函数。
<img src="img/draw.jpg" class="drag"> 在页面中插入一张图片。


  ///pc/homepage/javascript/sample/img/blank.gif" width="1" height="1">  
 

 

网页制作 网页设计 网站建设 网站设计 网站制作 做网站 做网页