UI (User Interface) Event, triggered when the user interacts with elements on the page
Load event: When the page is fully loaded, The load event on the window will be triggered.
Unload event: Triggered after the document is completely unloaded. Fires whenever the user switches from one page to another.
Resize event: When the browser adjusts to a new height or width, the resize event is triggered. Be careful not to add calculation logic to this event to avoid performance problems.
EventUtil.addHandler(window, "resize", function (event) { //防抖函数 //每次调用函数都会清除之前的计数器,并重新计数,计数完成时,执行操作。 var timer; return function () { if (timer) { clearTimeout(timer); } timer = setTimeout(function () { //setTimeout返回唯一标识符,可以使用它来取消计数器 console.log("123"); },500); } }());//此处的双括号表示,立即调用返回值
Scroll event: When the user scrolls the content in the element with a flow bar, it is triggered on the element.
EventUtil.addHandler(window, "scroll", function (event) { //函数节流 var timer; return function () { if (timer) { clearTimeout(timer); } timer = setTimeout(function () { //setTimeout返回唯一标识符,可以使用它来取消计数器 if (document.compatMode == "CSS1Compat") { //标准模式 console.log("Left:" + document.documentElement.scrollLeft); console.log("Top:" + document.documentElement.scrollTop); } else { //混杂模式 console.log("Left:" + document.body.scrollLeft); console.log("Top:" + document.body.scrollTop); } }, 500); } }());
Focus event, Triggered when the page gains or loses focus
Blur event: Triggered when the element loses focus. This event does not bubble; all browsers support it;
Focus event: triggered when the element gains focus. This event does not bubble up and is supported by all browsers;
Focusin event: triggered when an element gains focus. This event is equivalent to the HTML event focus, but it bubbles. The browsers that support this event are IE5, safari5.1, Opera11.5 and Chrome;
Focusout event: Triggered when the element is lost. This event is a universal version of the HTML event blur. The browsers that support this event are IE5 safari5.1 Opera11.5 and Chrome;
Mouse and wheel events
Click event: Triggered when the user clicks the left mouse button or presses the Enter key.
DbClick event: Triggered when the user double-clicks the left mouse button.
MouseDown event: Triggered when the user presses any mouse button.
MouseEnter event: Triggered when the mouse moves into the element range for the first time from outside.
MouseLeave event: Triggered when the mouse moves out of the scope of the element.
MouseMove event: Fired repeatedly when the mouse pointer moves inside the element.
MouseOut event: Triggered when the mouse pointer is over an element and the user moves it into another element.
MouseOver event: Triggered when the mouse pointer is outside an element and then the user moves it within the boundaries of another element for the first time.
MouseUp: Triggered when the user releases the mouse pointer.
Several mouse coordinate positions:
1. Client area coordinate position
Mouse events occur at specific positions in the browser viewport. This position is saved in the clientX and clientY properties of the event object.
2. Page coordinate position
pageX and pageY can tell you where the event occurred on the page. In other words, these two properties represent the position of the cursor in the page, so the coordinates are calculated from the page itself rather than from the left or top edge of the viewport.
When the page is not scrolled, pageX and pageY are equal to clientX and clientY.
IE8 and earlier versions do not support page coordinate position, but it can be calculated using the client area coordinate position and scroll information.
EventUtil.addHandler(document.getElementById("p1"), "click", function (event) { //兼容IE8及之前版本 event = EventUtil.getEvent(event); var pageX = event.pageX, pageY = event.pageY; if (pageX === undefined) { pageX = event.clientX + (document.body.scrollLeft || document.documentElement.scrollLeft); } if (pageY === undefined) { pageY = event.clientY + (document.body.scrollTop || document.documentElement.scrollTop); } //console.log("pageX:" + pageX); //console.log("pageY:" + pageY); });
3. Screen coordinate position
The screenX and screenY properties can determine the coordinate information of the mouse pointer relative to the entire screen when a mouse event occurs.
Related recommendations:
Compilation of common JavaScript error-prone knowledge points
The above is the detailed content of Latest collection of common JavaScript event types. For more information, please follow other related articles on the PHP Chinese website!

JavaScript originated in 1995 and was created by Brandon Ike, and realized the language into C. 1.C language provides high performance and system-level programming capabilities for JavaScript. 2. JavaScript's memory management and performance optimization rely on C language. 3. The cross-platform feature of C language helps JavaScript run efficiently on different operating systems.

JavaScript runs in browsers and Node.js environments and relies on the JavaScript engine to parse and execute code. 1) Generate abstract syntax tree (AST) in the parsing stage; 2) convert AST into bytecode or machine code in the compilation stage; 3) execute the compiled code in the execution stage.

The future trends of Python and JavaScript include: 1. Python will consolidate its position in the fields of scientific computing and AI, 2. JavaScript will promote the development of web technology, 3. Cross-platform development will become a hot topic, and 4. Performance optimization will be the focus. Both will continue to expand application scenarios in their respective fields and make more breakthroughs in performance.

Both Python and JavaScript's choices in development environments are important. 1) Python's development environment includes PyCharm, JupyterNotebook and Anaconda, which are suitable for data science and rapid prototyping. 2) The development environment of JavaScript includes Node.js, VSCode and Webpack, which are suitable for front-end and back-end development. Choosing the right tools according to project needs can improve development efficiency and project success rate.

Yes, the engine core of JavaScript is written in C. 1) The C language provides efficient performance and underlying control, which is suitable for the development of JavaScript engine. 2) Taking the V8 engine as an example, its core is written in C, combining the efficiency and object-oriented characteristics of C. 3) The working principle of the JavaScript engine includes parsing, compiling and execution, and the C language plays a key role in these processes.

JavaScript is at the heart of modern websites because it enhances the interactivity and dynamicity of web pages. 1) It allows to change content without refreshing the page, 2) manipulate web pages through DOMAPI, 3) support complex interactive effects such as animation and drag-and-drop, 4) optimize performance and best practices to improve user experience.

C and JavaScript achieve interoperability through WebAssembly. 1) C code is compiled into WebAssembly module and introduced into JavaScript environment to enhance computing power. 2) In game development, C handles physics engines and graphics rendering, and JavaScript is responsible for game logic and user interface.

JavaScript is widely used in websites, mobile applications, desktop applications and server-side programming. 1) In website development, JavaScript operates DOM together with HTML and CSS to achieve dynamic effects and supports frameworks such as jQuery and React. 2) Through ReactNative and Ionic, JavaScript is used to develop cross-platform mobile applications. 3) The Electron framework enables JavaScript to build desktop applications. 4) Node.js allows JavaScript to run on the server side and supports high concurrent requests.


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

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

SublimeText3 Chinese version
Chinese version, very easy to use

WebStorm Mac version
Useful JavaScript development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SublimeText3 Mac version
God-level code editing software (SublimeText3)
