2010-06-25 48 views
0

我使用以下代碼來允許用戶垂直調整DIV元素的大小,但是當單擊並拖動頁面上的句柄,文本和其他元素時,用戶只需點擊並突出顯示頁面上的所有內容。有沒有辦法阻止這種情況發生,因爲這看起來很糟糕?這與Prototype.js一起使用。JavaScript拖動選擇拖動區域周圍的文本和元素

function DragCorner(container, handle) { 
    var container = $(container); 
    var handle = $(handle); 

    // Add property to container to store position variables 
    container.moveposition = {y:0}; 

    function moveListener(event) { 
     // Calculate how far the mouse moved 
     var moved = { y:(container.moveposition.y - event.pointerY()) }; 
     // Reset container's x/y utility property 
     container.moveposition = {y:event.pointerY()}; 
     // Update container's size 
     var size = container.getDimensions(); 
     container.setStyle({height: size.height + moved.y + 'px'}); 
    } 

    // Listen for 'mouse down' on handle to start the move listener 
    handle.observe('mousedown', function(event) { 
     // Set starting x/y 
     container.moveposition = {y:event.pointerY()}; 
     // Start listening for mouse move on body 
     Event.observe(document.body,'mousemove',moveListener); 
    }); 

    // Listen for 'mouse up' to cancel 'move' listener 
    Event.observe(document.body,'mouseup', function(event) { 
     Event.stopObserving(document.body,'mousemove',moveListener); 
     console.log('stop listening'); 
    }); 
} 

回答

0

添加下面的DIV固定這樣的:

onselectstart="return false;" 
0

跟進你剛纔的問題和答案,添加一個小手柄元素,並使其作爲可以選擇並拖動的唯一因素。此外,我想你已經把這個div的位置設爲relative,並且處理位置爲absolute。對??

+0

股利是固定的,我有一個手柄DIV是附加到我拉伸div的頂部一個div。 – 2010-06-25 21:44:38