From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../api/globaleventhandlers/ondragleave/index.html | 196 +++++++++++++++++++++ 1 file changed, 196 insertions(+) create mode 100644 files/zh-cn/web/api/globaleventhandlers/ondragleave/index.html (limited to 'files/zh-cn/web/api/globaleventhandlers/ondragleave/index.html') diff --git a/files/zh-cn/web/api/globaleventhandlers/ondragleave/index.html b/files/zh-cn/web/api/globaleventhandlers/ondragleave/index.html new file mode 100644 index 0000000000..bce1cf2d8d --- /dev/null +++ b/files/zh-cn/web/api/globaleventhandlers/ondragleave/index.html @@ -0,0 +1,196 @@ +--- +title: GlobalEventHandlers.ondragleave +slug: Web/API/GlobalEventHandlers/ondragleave +translation_of: Web/API/GlobalEventHandlers/ondragleave +--- +
{{ApiRef("HTML DOM")}}
+ +

A {{domxref("GlobalEventHandlers","global event handler")}} for the {{event("dragleave")}} event.

+ +

Syntax

+ +
var dragleaveHandler = targetElement.ondragleave;
+
+ +

Return value

+ +
+
dragleaveHandler
+
The dragleave event handler for element targetElement.
+
+ +

Example

+ +

This example demonstrates using the {{domxref("GlobalEventHandlers.ondragleave","ondragleave")}} attribute handler to set an element's {{event("dragleave")}} event handler.

+ +
<!DOCTYPE html>
+<html lang=en>
+<title>Examples of using the Drag and Drop Global Event Attribute</title>
+<meta content="width=device-width">
+<style>
+  div {
+    margin: 0em;
+    padding: 2em;
+  }
+  #source {
+    color: blue;
+    border: 1px solid black;
+  }
+  #target {
+    border: 1px solid black;
+  }
+</style>
+</head>
+<script>
+function dragstart_handler(ev) {
+ console.log("dragStart");
+ // Change the source element's border to signify drag has started
+ ev.currentTarget.style.border = "dashed";
+ ev.dataTransfer.setData("text", ev.target.id);
+}
+
+function dragover_handler(ev) {
+ console.log("dragOver");
+ // Change the target element's background color to signify a drag over event
+ // has occurred
+ ev.currentTarget.style.background = "lightblue";
+ ev.preventDefault();
+}
+
+function drop_handler(ev) {
+ console.log("Drop");
+ ev.preventDefault();
+ var data = ev.dataTransfer.getData("text");
+ ev.target.appendChild(document.getElementById(data));
+}
+
+function dragenter_handler(ev) {
+ console.log("dragEnter");
+ // Change the source element's background color for enter events
+ ev.currentTarget.style.background = "yellow";
+}
+
+function dragleave_handler(ev) {
+ console.log("dragLeave");
+ // Change the source element's background color back to white
+ ev.currentTarget.style.background = "white";
+}
+
+function dragend_handler(ev) {
+ console.log("dragEnd");
+ // Change the target element's background color to visually indicate
+ // the drag ended.
+ var el=document.getElementById("target");
+ el.style.background = "pink";
+}
+
+function dragexit_handler(ev) {
+ console.log("dragExit");
+ // Change the source element's background color back to green to signify a dragexit event
+ ev.currentTarget.style.background = "green";
+}
+
+function init() {
+ // Set handlers for the source's enter/leave/end/exit events
+ var el=document.getElementById("source");
+ el.ondragenter = dragenter_handler;
+ el.ondragleave = dragleave_handler;
+ el.ondragend = dragend_handler;
+ el.ondragexit = dragexit_handler;
+}
+</script>
+<body onload="init();">
+<h1>Examples of <code>ondragenter</code>, <code>ondragleave</code>, <code>ondragend</code>, <code>ondragexit</code></h1>
+ <div>
+   <p id="source" ondragstart="dragstart_handler(event);" draggable="true">
+     Select this element, drag it to the Drop Zone and then release the selection to move the element.</p>
+ </div>
+ <div id="target" ondrop="drop_handler(event);" ondragover="dragover_handler(event);">Drop Zone</div>
+</body>
+</html>
+
+
+ +

Specifications

+ + + + + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName("HTML WHATWG", "indices.html#ix-handler-ondragleave", "ondragleave")}}{{Spec2("HTML WHATWG")}} 
{{SpecName("HTML5.1", "index.html#ix-handler-ondragleave", "ondragleave")}}{{Spec2("HTML5.1")}}Initial definition
+ +

Browser compatibility

+ +

{{CompatibilityTable}}

+ +
+ + + + + + + + + + + + + + + + + + + +
FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari (WebKit)
Basic support4{{CompatGeckoDesktop("1.9.1")}}10123.1
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
FeatureAndroidAndroid WebviewChrome for AndroidFirefox Mobile (Gecko)Firefox OSIE MobileOpera MobileSafari Mobile
Basic support{{CompatNo}}{{CompatNo}}{{CompatNo}}{{CompatNo}}{{CompatNo}}{{CompatIE("10")}}{{CompatNo}}{{CompatNo}}
+
+ +

See also

+ + -- cgit v1.2.3-54-g00ecf