欧美一区二区三区,国内熟女精品熟女A片视频小说,日本av网,小鲜肉男男GAY做受XXX网站

HTML事件屬性ondragleave


HTML事件屬性ondragleave


觸發ondragleave屬性事件當可拖動元素或文本選擇離開放置目標時。

要使元素可拖動,請標記該元素與全局HTML5draggable屬性。

默認情況下,鏈接和圖像是可拖動的。

在draggable源元素上觸發的事件:

  • ondragstart - starting dragging
  • ondrag - during the dragging
  • ondragend - finish dragging

投放目標上觸發的事件:

  • ondragenter - when the dragged element enters the droppable target
  • ondragover - when the dragged element is over the droppable target
  • ondragleave - when the dragged element leaves the droppable target
  • ondrop - when the dragged element is dropped on the droppable target


HTML5中的新功能

ondragleave屬性是HTML5中的新特性。

句法

<element ondragleave="script or Javascript function name">

支持的標簽

所有HTML元素

瀏覽器兼容性

HTML事件屬性ondragleaveHTML事件屬性ondragleaveHTML事件屬性ondragleaveHTML事件屬性ondragleaveHTML事件屬性ondragleave
ondragleaveYes9.0YesYesYes

例子

<!DOCTYPE HTML>
<html>
<head>
<style>
.droptarget {float:left;width: 100px;height: 35px;margin: 15px;padding: 10px;border: 1px solid red;
}
</style>
</head>
<body>

<div class="droptarget" ondrop="drop(event)" ondragenter="dragEnter(event)"  
   ondragover="allowDrop(event)"
   ondragleave="dragLeave(event)">
  <p ondragstart="dragStart(event)" 
     ondrag="dragging(event)" 
     draggable="true" 
     id="dragtarget">Drag me!</p>
</div>

<div class="droptarget" 
    ondrop="drop(event)" ondragover="allowDrop(event)"></div>

<script>
function dragStart(event) {
    event.dataTransfer.setData("Text", event.target.id);
}
function dragLeave(event) {
    console.log("dragLeave");
}

function dragEnter(event) {
    console.log("enter");
}
function dragging(event) {
    console.log("being dragged");
}

function allowDrop(event) {
    event.preventDefault();
}

function drop(event) {
    event.preventDefault();vardata = event.dataTransfer.getData("Text");
    event.target.appendChild(document.getElementById(data));
    console.log("dropped");
}
</script>

</body>
</html>

Click to view the demo