午夜国产狂喷潮在线观看|国产AⅤ精品一区二区久久|中文字幕AV中文字幕|国产看片高清在线

    頁(yè)面元素可拖拽放置的實(shí)現(xiàn)原理
    來(lái)源:易賢網(wǎng) 閱讀:888 次 日期:2015-04-22 11:25:44
    溫馨提示:易賢網(wǎng)小編為您整理了“頁(yè)面元素可拖拽放置的實(shí)現(xiàn)原理”,方便廣大網(wǎng)友查閱!

    基本上msn、microsoft Live 和GOOGLE個(gè)性主頁(yè) 元素可拖動(dòng)并放置的的實(shí)現(xiàn)原理就是對(duì)DOM的操作再加上JAVASCRIPT拖動(dòng)元素。實(shí)現(xiàn)起來(lái)實(shí)際上并不難,但是要做到很美觀并符合用戶習(xí)慣就需要一些時(shí)間思考了。

    以下代碼實(shí)現(xiàn)了上述功能,雖然很簡(jiǎn)單,但是基本上說(shuō)明了原理。實(shí)現(xiàn)更高級(jí)的功能當(dāng)然還需要改進(jìn)。

    <!doctype HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >

    <html>

    <head>

    <title>DropLayer2</title>

    <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">

    <meta name="CODE_LANGUAGE" Content="C#">

    <meta name="vs_defaultClientScript" content="JavaScript">

    <meta name="vs_targetSchema" content="">

    <style type="text/css">

    div

    {

    border-right: lightgrey thin solid;

    border-top: lightgrey thin solid;

    font-weight: bold;

    z-index: 2;

    text-transform: capitalize;

    border-left: lightgrey thin solid;

    color: white;

    border-bottom: lightgrey thin solid;

    background-color: dimgray;

    }

    </style>

    </head>

    <body>

    <div id="parentDiv" class="parentCss" style="width:100">

    <div class="itemCss" onmouseover="InsertDiv(this)">one 1</div>

    <div class="itemCss" onmouseover="InsertDiv(this)">two 2</div>

    <div class="itemCss" onmouseover="InsertDiv(this)">three 3</div>

    <div class="itemCss" onmouseover="InsertDiv(this)">four 4</div>

    <div class="itemCss" onmouseover="InsertDiv(this)">five 5</div>

    <div class="itemCss" onmouseover="InsertDiv(this)">six 6</div>

    <div class="itemCss" onmouseover="InsertDiv(this)">seven 7</div>

    <div class="itemCss" onmouseover="InsertDiv(this)">eight 8</div>

    <div class="itemCss" onmouseover="InsertDiv(this)">nine 9</div>

    <div class="itemCss" onmouseover="InsertDiv(this)">ten 10</div>

    </div>

    <script language="javascript">

    <!--

    var obj,obj2; //引發(fā)事件對(duì)象

    var rootNode; //控制對(duì)象根節(jié)點(diǎn)

    var IsDrag=false; //是否抓起

    var NullDiv; //空臨時(shí)層

    var x,y; //鼠標(biāo)與控件的相對(duì)坐標(biāo)

    window.onload = Prepare; //窗體加載時(shí)委托到Prepare

    function Prepare()

    {

    //生成臨時(shí)層,并設(shè)置其屬性

    NullDiv = document.createElement("div");

    //獲得控制對(duì)象的根節(jié)點(diǎn)元素

    rootNode = document.getElementById("parentDiv");

    document.onmousemove=MoveIt; //當(dāng)鼠標(biāo)在文檔上移動(dòng)時(shí)事件委托到MoveIt

    document.onmousedown=Drag; //當(dāng)鼠標(biāo)按下時(shí)事件委托到Drag

    document.onmouseup=Release; //當(dāng)鼠標(biāo)釋放臺(tái)起時(shí)事件委托到Release

    }

    function Drag()

    {

    obj = event.srcElement;

    x=0;//event.offsetX;

    y=0;//event.offsetY;

    obj.style.position='absolute';

    obj.style.posTop=event.y-y;

    obj.style.posLeft=event.x-x;

    IsDrag=true;

    }

    function MoveIt()

    {

    //window.status = event.x+"|"+event.y+"|"+IsDrag+"|"+x+"|"+y;

    if(IsDrag)

    {

    obj.style.posTop=event.y-y;

    obj.style.posLeft=event.x-x;

    }

    }

    function Release()

    {

    IsDrag=false;

    NullDiv.style.display='none';

    obj.style.position='';

    rootNode.insertBefore(obj,obj2);

    }

    function InsertDiv(o)

    {

    if(IsDrag)

    {

    obj2=o;

    NullDiv.style.display='';

    NullDiv.style.height='18';

    NullDiv.style.width='100';

    rootNode.insertBefore(NullDiv,obj2);

    }

    }

    //-->

    </script>

    </body>

    </html>

    更多信息請(qǐng)查看IT技術(shù)專欄

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

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

    • 報(bào)班類型
    • 姓名
    • 手機(jī)號(hào)
    • 驗(yàn)證碼
    關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡(jiǎn)要咨詢 | 簡(jiǎn)要咨詢須知 | 新媒體/短視頻平臺(tái) | 手機(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:1093837350(9:00—18:00)版權(quán)所有:易賢網(wǎng)
    云南網(wǎng)警報(bào)警專用圖標(biāo)