Dreamweaver 的層可以在頁面內拖動,但要做成整個螢幕都能拖的浮動小視窗就傷腦筋了。以下是一種可行的做法。
準備一張圖片,命名為 back.jpg。

新增一個 htm 檔取名 drag.htm,寫入下列程式碼:
<html>
<head>
<title>可拖動的圖片</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body bgcolor="#FFFFFF" text="#000000" scroll=no topmargin=0 leftmargin=0 onmousedown="x=event.x;y=event.y;setCapture()" onmouseup="releaseCapture()" onmousemove="if(event.button==1)top.moveTo(screenLeft+event.x-x,screenTop+event.y-y)" ondblclick="self.close()">
<img src="back.jpg" width="120" height="120" style="cursor:hand;border:3 gold ridge">
</body>
</html>
drag.htm 就是那個能被拖動的頁面。
加上這段程式碼:
<head>
<title>可全螢幕拖動的圖片</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<script language="JavaScript">
function drag(){
var win;
win=window.open("drag.htm","","fullscreen");
win.moveTo(200,200);
win.resizeTo(126,126);
win.focus();
}
</script>
</head>
再用連結觸發:
<a href="javascript:drag()">點這裡</a>
關鍵在 drag.htm 的四個滑鼠事件。onmousedown 先記下按下時的游標座標並呼叫 setCapture() 捕獲滑鼠;onmousemove 在按住左鍵期間,用目前游標位置減去起始位移,再呼叫 moveTo() 讓整個視窗跟著移動;onmouseup 用 releaseCapture() 釋放捕獲。另外關掉了 scroll 與邊界留白,並加上 ondblclick="self.close()",雙擊就能關掉視窗。
呼叫端則用 window.open 搭配 fullscreen 參數開啟視窗,再用 moveTo 與 resizeTo 決定初始位置與大小。
存檔後預覽看看效果吧。