


The event ondragenter is triggered in H5 when the dragged element or selected text enters a valid drop target.
Example
Executed when the dragged element enters the drop targetJavaScript :
<div ondragenter="myFunction(event)"></div>
Definition and usage
ondragenter Event Triggered when the dragged element or selected text enters a valid drop target.
Ondragenter and ondragleave events can help users better understand the process of draggable elements entering and leaving the placement area. You can set different background colors when a draggable element enters and leaves the drop zone.
Drag and drop is a very common feature in HTML5. For more information, check out HTML5 Drag and Drop in our HTML tutorial.
Note: To make an element draggable, you need to use the HTML5 draggable attribute.
Tip: Links and images are draggable by default and do not require the draggable attribute.
The following events will be triggered during the drag and drop process:
Trigger events on the drag target (source element):
ondragstart - User Fires when you start dragging the element
ondrag - Fires when the element is being dragged
-
ondragend - Fires after the user completes dragging the element
Events triggered when the target is released:
ondragenter - This event is triggered when the object dragged by the mouse enters its container scope
ondragover - This event is triggered when a dragged object is dragged within the scope of another object container
ondragleave - When an object is dragged by the mouse This event is triggered when the object leaves the scope of its container
ondrop - This event is triggered when the mouse button is released during a drag process
Browser support
The number in the table indicates the version number of the first browser that supports this event.
Syntax
HTML:
<element ondragenter="myScript">
JavaScript:
object.ondragenter=function(){myScript};
JavaScript, use the addEventListener() method :
object.addEventListener("dragenter", myScript);
Note: Internet Explorer 8 and earlier IE versions do not support the addEventListener() method.
Technical details
Whether bubbling is supported: | Yes |
Can be canceled : | Yes |
Event type: | DragEvent |
Supported HTML tags: | All HTML elements |
更多实例
实例
以下实例演示了所有的拖放事件:
/* 拖动时触发*/ document.addEventListener("dragstart", function(event) { //dataTransfer.setData()方法设置数据类型和拖动的数据 event.dataTransfer.setData("Text", event.target.id); // 拖动 p 元素时输出一些文本 document.getElementById("demo").innerHTML = "开始拖动 p 元素."; //修改拖动元素的透明度 event.target.style.opacity = "0.4"; }); //在拖动p元素的同时,改变输出文本的颜色 document.addEventListener("drag", function(event) { document.getElementById("demo").style.color = "red"; }); // 当拖完p元素输出一些文本元素和重置透明度 document.addEventListener("dragend", function(event) { document.getElementById("demo").innerHTML = "完成 p 元素的拖动"; event.target.style.opacity = "1"; }); /* 拖动完成后触发 */ // 当p元素完成拖动进入droptarget,改变div的边框样式 document.addEventListener("dragenter", function(event) { if ( event.target.className == "droptarget" ) { event.target.style.border = "3px dotted red"; } }); // 默认情况下,数据/元素不能在其他元素中被拖放。对于drop我们必须防止元素的默认处理 document.addEventListener("dragover", function(event) { event.preventDefault(); }); // 当可拖放的p元素离开droptarget,重置div的边框样式 document.addEventListener("dragleave", function(event) { if ( event.target.className == "droptarget" ) { event.target.style.border = ""; } }); /*对于drop,防止浏览器的默认处理数据(在drop中链接是默认打开) 复位输出文本的颜色和DIV的边框颜色 利用dataTransfer.getData()方法获得拖放数据 拖拖的数据元素id("drag1") 拖拽元素附加到drop元素*/ document.addEventListener("drop", function(event) { event.preventDefault(); if ( event.target.className == "droptarget" ) { document.getElementById("demo").style.color = ""; event.target.style.border = ""; var data = event.dataTransfer.getData("Text"); event.target.appendChild(document.getElementById(data)); } });
The above is the detailed content of The event ondragenter is triggered in H5 when the dragged element or selected text enters a valid drop target.. For more information, please follow other related articles on the PHP Chinese website!

MicrodatainHTML5enhancesSEOanduserexperiencebyprovidingstructureddatatosearchengines.1)Useitemscope,itemtype,anditempropattributestomarkupcontentlikeproductsorevents.2)TestmicrodatawithtoolslikeGoogle'sStructuredDataTestingTool.3)ConsiderusingJSON-LD

HTML5introducesnewinputtypesthatenhanceuserexperience,simplifydevelopment,andimproveaccessibility.1)automaticallyvalidatesemailformat.2)optimizesformobilewithanumerickeypad.3)andsimplifydateandtimeinputs,reducingtheneedforcustomsolutions.

H5 is HTML5, the fifth version of HTML. HTML5 improves the expressiveness and interactivity of web pages, introduces new features such as semantic tags, multimedia support, offline storage and Canvas drawing, and promotes the development of Web technology.

Accessibility and compliance with network standards are essential to the website. 1) Accessibility ensures that all users have equal access to the website, 2) Network standards follow to improve accessibility and consistency of the website, 3) Accessibility requires the use of semantic HTML, keyboard navigation, color contrast and alternative text, 4) Following these principles is not only a moral and legal requirement, but also amplifying user base.

The H5 tag in HTML is a fifth-level title that is used to tag smaller titles or sub-titles. 1) The H5 tag helps refine content hierarchy and improve readability and SEO. 2) Combined with CSS, you can customize the style to enhance the visual effect. 3) Use H5 tags reasonably to avoid abuse and ensure the logical content structure.

The methods of building a website in HTML5 include: 1. Use semantic tags to define the web page structure, such as, , etc.; 2. Embed multimedia content, use and tags; 3. Apply advanced functions such as form verification and local storage. Through these steps, you can create a modern web page with clear structure and rich features.

A reasonable H5 code structure allows the page to stand out among a lot of content. 1) Use semantic labels such as, etc. to organize content to make the structure clear. 2) Control the rendering effect of pages on different devices through CSS layout such as Flexbox or Grid. 3) Implement responsive design to ensure that the page adapts to different screen sizes.

The main differences between HTML5 (H5) and older versions of HTML include: 1) H5 introduces semantic tags, 2) supports multimedia content, and 3) provides offline storage functions. H5 enhances the functionality and expressiveness of web pages through new tags and APIs, such as and tags, improving user experience and SEO effects, but need to pay attention to compatibility issues.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SublimeText3 Chinese version
Chinese version, very easy to use
