页面图片浏览

在页面上浏览图片,实现图片的拖放

  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
  4. <title>位图浏览器</title>
  5. <style type="text/css">
  6. <!--
  7. #pic {
  8.     width:1000px;
  9.     height:600px;
  10.     border: 3px solid #ccc;
  11.     background-repeat: no-repeat;
  12.     background-position: 0px 0px;
  13.     cursor: pointer ;
  14. }
  15. -->
  16. </style>
  17. <script language="javascript" src="Request.js"></script>
  18. <script type="text/javascript">
  19. <!--
  20. var p = new Array();
  21. var speed = 0.05;  //速度
  22. var picWidth = 10000;  // 大图的宽高
  23. var picHeight = 10000;
  24. var x,y // 鼠标点下去时背景的坐标
  25. var x_new,y_new  //位移
  26. var haveclick = false;
  27. function getmouseposition(event)
  28. {
  29.     if(document.all)
  30.     {
  31.         x = document.body.scrollLeft+event.clientX;
  32.         y = document.body.scrollTop+event.clientY;
  33.     }else
  34.     {
  35.         x = event.layerX;
  36.         y = event.layerY;
  37.     }   
  38.     haveclick = true;
  39. }
  40. function movestop()
  41. {
  42.     haveclick = false;
  43. }
  44. function movestart(event)
  45. {
  46. if(haveclick)
  47. {
  48.     if(document.getElementById('pic').style.backgroundPosition.length==0)
  49.         {document.getElementById('pic').style.backgroundPosition="0px 0px";}
  50.     p = document.getElementById('pic').style.backgroundPosition.split(" ")
  51.     if(document.all)
  52.     {   
  53.         x_new = document.body.scrollLeft+event.clientX;
  54.         y_new = document.body.scrollTop+event.clientY;
  55.     }else
  56.     {    
  57.         x_new = event.layerX;
  58.         y_new = event.layerY;   
  59.     }
  60.     
  61.     x2 = (speed*(x_new-x)+parseInt(p[0])).toString(10);    // 计算位移量
  62.     y2 = (speed*(y_new-y)+parseInt(p[1])).toString(10);
  63.     
  64.     if (x2<-picWidth+420) x2=-picWidth+420;
  65.     if (y2>0) y2=0;
  66.     if (x2>0) x2=0;
  67.     if (y2<-picHeight+300) y2=-picHeight+300;
  68.     document.getElementById('pic').style.backgroundPosition=x2+"px "+y2+"px";
  69. }
  70. }
  71. function SetImageUrl()
  72. {
  73.     self.moveTo(0,0);
  74.     self.resizeTo(screen.availWidth,screen.availHeight);  
  75.     var IMGURL = "" ;
  76.     document.getElementById('pic').style.backgroundImage = "url("+IMGURL+")" ;
  77. }
  78. -->
  79. </script>
  80. </head>
  81. <body onload="SetImageUrl()">
  82. <TABLE width="100%">
  83. <TR>
  84. <TD align="center">
  85. <div id="pic" onmousedown="getmouseposition(event)" onmousemove="movestart(event)" onmouseup="movestop()" onmouseout="movestop()"> </div>
  86. </TD>
  87. </TR>
  88. </TABLE>
  89. </body>
  90. </html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值