可移動(dòng)的圖層
來源:易賢網(wǎng) 閱讀:1013 次 日期:2016-06-29 09:05:02
溫馨提示:易賢網(wǎng)小編為您整理了“可移動(dòng)的圖層”,方便廣大網(wǎng)友查閱!

1、將以下代碼加入到heml的<head></head>之間:

<style type=text/css>

#floater {

position: absolute;

left: 500;

top: 146;

width: 125;

visibility: visible;

z-index: 10;

}</style>

====2、將以下代碼加入到heml的<body></body>之間

<div id=floater style=left: 590px; top: 158px>

<p align=center><img src=想要顯示的圖片.gif alt=圖片顯示的文字 width=125 height=60><br>

<font color=#ff8040>圖片下面的文字</font></p>

</div><script language=javascript>

self.onerror=null;

currentx = currenty = 0;

whichit = null;

lastscrollx = 0; lastscrolly = 0;

ns = (document.layers) ? 1 : 0;

ie = (document.all) ? 1: 0;

<!-- stalker code -->

function heartbeat() {

if(ie) { diffy = document.body.scrolltop; diffx = document.body.scrollleft; }

if(ns) { diffy = self.pageyoffset; diffx = self.pagexoffset; }

if(diffy != lastscrolly) {

percent = .1 * (diffy - lastscrolly);

if(percent > 0) percent = math.ceil(percent);

else percent = math.floor(percent);

if(ie) document.all.floater.style.pixeltop += percent;

if(ns) document.floater.top += percent;

lastscrolly = lastscrolly + percent;

}

if(diffx != lastscrollx) {

percent = .1 * (diffx - lastscrollx);

if(percent > 0) percent = math.ceil(percent);

else percent = math.floor(percent);

if(ie) document.all.floater.style.pixelleft += percent;

if(ns) document.floater.left += percent;

lastscrollx = lastscrollx + percent;

}

}

<!-- /stalker code -->

<!-- drag drop code -->

function checkfocus(x,y) {

stalkerx = document.floater.pagex;

stalkery = document.floater.pagey;

stalkerwidth = document.floater.clip.width;

stalkerheight = document.floater.clip.height;

if( (x > stalkerx && x < (stalkerx+stalkerwidth)) && (y > stalkery && y < (stalkery+stalkerheight))) return true;

else return false;

}

function grabit(e) {

if(ie) {

whichit = event.srcelement;

while (whichit.id.indexof(floater) == -1) {

whichit = whichit.parentelement;

if (whichit == null) { return true; }

}

whichit.style.pixelleft = whichit.offsetleft;

whichit.style.pixeltop = whichit.offsettop;

currentx = (event.clientx + document.body.scrollleft);

currenty = (event.clienty + document.body.scrolltop);

} else {

window.captureevents(event.mousemove);

if(checkfocus (e.pagex,e.pagey)) {

whichit = document.floater;

stalkertouchedx = e.pagex-document.floater.pagex;

stalkertouchedy = e.pagey-document.floater.pagey;

}

}

return true;

}

function moveit(e) {

if (whichit == null) { return false; }

if(ie) {

newx = (event.clientx + document.body.scrollleft);

newy = (event.clienty + document.body.scrolltop);

distancex = (newx - currentx); distancey = (newy - currenty);

currentx = newx; currenty = newy;

whichit.style.pixelleft += distancex;

whichit.style.pixeltop += distancey;

if(whichit.style.pixeltop < document.body.scrolltop) whichit.style.pixeltop = document.body.scrolltop;

if(whichit.style.pixelleft < document.body.scrollleft) whichit.style.pixelleft = document.body.scrollleft;

if(whichit.style.pixelleft > document.body.offsetwidth - document.body.scrollleft - whichit.style.pixelwidth - 20) whichit.style.pixelleft = document.body.offsetwidth - whichit.style.pixelwidth - 20;

if(whichit.style.pixeltop > document.body.offsetheight + document.body.scrolltop - whichit.style.pixelheight - 5) whichit.style.pixeltop = document.body.offsetheight + document.body.scrolltop - whichit.style.pixelheight - 5;

event.returnvalue = false;

} else {

whichit.moveto(e.pagex-stalkertouchedx,e.pagey-stalkertouchedy);

if(whichit.left < 0+self.pagexoffset) whichit.left = 0+self.pagexoffset;

if(whichit.top < 0+self.pageyoffset) whichit.top = 0+self.pageyoffset;

if( (whichit.left + whichit.clip.width) >= (window.innerwidth+self.pagexoffset-17)) whichit.left = ((window.innerwidth+self.pagexoffset)-whichit.clip.width)-17;

if( (whichit.top + whichit.clip.height) >= (window.innerheight+self.pageyoffset-17)) whichit.top = ((window.innerheight+self.pageyoffset)-whichit.clip.height)-17;

return false;

}

return false;

}

function dropit() {

whichit = null;

if(ns) window.releaseevents (event.mousemove);

return true;

}

<!-- drag drop code -->

if(ns) {

window.captureevents(event.mouseup|event.mousedown);

window.onmousedown = grabit;

window.onmousemove = moveit;

window.onmouseup = dropit;

}

if(ie) {

document.onmousedown = grabit;

document.onmousemove = moveit;

document.onmouseup = dropit;

}

if(ns || ie) action = window.setinterval(heartbeat(),1);

</script>

更多信息請(qǐng)查看腳本欄目
易賢網(wǎng)手機(jī)網(wǎng)站地址:可移動(dòng)的圖層
由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復(fù)僅供參考,敬請(qǐng)考生以權(quán)威部門公布的正式信息和咨詢?yōu)闇?zhǔn)!

2025國(guó)考·省考課程試聽報(bào)名

  • 報(bào)班類型
  • 姓名
  • 手機(jī)號(hào)
  • 驗(yàn)證碼
關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡(jiǎn)要咨詢 | 簡(jiǎn)要咨詢須知 | 加入群交流 | 手機(jī)站點(diǎn) | 投訴建議
工業(yè)和信息化部備案號(hào):滇ICP備2023014141號(hào)-1 云南省教育廳備案號(hào):云教ICP備0901021 滇公網(wǎng)安備53010202001879號(hào) 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號(hào)
云南網(wǎng)警備案專用圖標(biāo)
聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關(guān)注公眾號(hào):hfpxwx
咨詢QQ:526150442(9:00—18:00)版權(quán)所有:易賢網(wǎng)
云南網(wǎng)警報(bào)警專用圖標(biāo)