This article brings you relevant knowledge about javascript, which mainly introduces related issues about common JavaScript event types, including mouse events, keyboard events, etc. Let’s talk about it together Take a look, hope it helps everyone.
[Related recommendations: javascript video tutorial, web front-end】
Mouse event
Event Type
- click: The user clicks the main mouse button (usually the left button) or presses the Enter key while focusing Triggered when
- dblclick: Triggered when the user double-clicks the main mouse button (frequency depends on the system configuration)
- mousedown: Triggered when the user presses any mouse button
- mouseup: Triggered when the user lifts Triggered when any mouse button is pressed
- mousemove: Triggered when the mouse moves on the element
- mouseover: Triggered when the mouse enters the element
- mouseout: Triggered when the mouse leaves the element
- mouseenter: Triggered when the mouse enters the element, the event will not bubble
- mouseleave: Triggered when the mouse leaves the element, the event will not bubble
Difference:
- over and out, regardless of the child element, moving from the parent element to the child element, for the parent element, is still counted as leaving
- enter and leave, consider child elements, which are still part of the parent element
- mouseenter and mouseleave will not bubble
Event object
All mouse events and event objects in the event handler are MouseEvent
- altKey: When the event is triggered, whether the alt key of the keyboard is pressed
- ctrlKey: When the event is triggered, whether the ctrl key of the keyboard is pressed
- shiftKey: When the event is triggered, whether the shift key of the keyboard is pressed
- button: When the event is triggered, Mouse button type
- 0: Left button
- 1: Middle button
- 2: Right button
##Position
- page: pageX, pageY, the horizontal and vertical coordinates of the current mouse distance from the page
- client: clientX, clientY, the mouse is relative to the viewport The coordinates
- offset: offsetX, offsetY, the coordinates of the mouse relative to the padding of the event source
- screen: screenX, screenY, the mouse relative to the screen
- x, y , equivalent to clientX, clientY
- movement: movementX, movementY, only valid in mouse movement events, relative to the last mouse position, offset distance
Event type
- keydown: Triggered by pressing any key on the keyboard. If pressed and held down, this event will be triggered repeatedly
- keypress: Triggered when pressing a
- character key on the keyboard keyup: Triggered by lifting any key on the keyboard
Event object
KeyboardEvent- code: Get the key string and adapt to the keyboard layout.
- key: Get the key string, which does not fit the keyboard layout. Can get printed characters.
- keyCode, which: get the keyboard code
Form event
- focus: the element is focused Triggered when the element can interact with the user (all elements that can interact with the user can be focused), the event will not bubble
- blur: Triggered when the element loses focus, the event will not bubble.
- submit: Submit form event, only valid in form elements.
- change: text change event
- input: text change event, trigger immediately
- load, DOMContentLoaded, readystatechange
Image load: event that image resources have been loaded
The process of browser rendering the page:DOMContentLoaded of document: Occurs after the dom tree is builtreadystate (the page has three statesGet the page source code
- Create the document node
- Add elements to the dom tree in sequence from top to bottom , each time an element is added, pre-rendering
- Renders the child nodes in sequence according to the structure
): loading (loading), interactive (interactive), complete (complete)
js code should be written to the bottom of the page as much as possible
css should be written to the top of the page: avoid flickering (if placed at the bottom of the page, it will cause the element to have no style first, use the ugly default style, and then when the css is read file, re-change the style)
JS should be written to the bottom of the page: to avoid blocking subsequent rendering, and to avoid not getting the content in the page when running JS element.
unload, beforeunload
beforeunload: window event, runs when the window is closed, and can prevent the window from closing
unload: window event , runs when the window is closed
- scroll
Events run when the window scrolls
Through scrollTop and scrollLeft, the scroll distance can be obtained and set.
- resize
Events run when the window size changes, monitoring the viewport size
- contextmenu
Right-click menu event
- paste
Paste event
- copy
Copy event
- cut
A few distance pictures
##Element position
- offsetParent
- offsetLeft, offsetTop //The distance from the positioned element is the distance from body
- getBoundingClientRect method
Event simulation
- click simulated click
- sumbit simulation Submit form
- dispatchEvent simulation event
- window.scrollX, window.pageXOffset, window.scrollY, window.pageYOffset
- scrollTo, scrollBy
scrollBy: means to increase the x and y axis distance from the window based on the original. scrollBy(x, y)
- resizeTo, resizeBy
javascript video tutorial, web front-end]
The above is the detailed content of Organizing common event types in JavaScript. For more information, please follow other related articles on the PHP Chinese website!

JavaScriptusestwotypesofcomments:single-line(//)andmulti-line(//).1)Use//forquicknotesorsingle-lineexplanations.2)Use//forlongerexplanationsorcommentingoutblocksofcode.Commentsshouldexplainthe'why',notthe'what',andbeplacedabovetherelevantcodeforclari

The main difference between Python and JavaScript is the type system and application scenarios. 1. Python uses dynamic types, suitable for scientific computing and data analysis. 2. JavaScript adopts weak types and is widely used in front-end and full-stack development. The two have their own advantages in asynchronous programming and performance optimization, and should be decided according to project requirements when choosing.

Whether to choose Python or JavaScript depends on the project type: 1) Choose Python for data science and automation tasks; 2) Choose JavaScript for front-end and full-stack development. Python is favored for its powerful library in data processing and automation, while JavaScript is indispensable for its advantages in web interaction and full-stack development.

Python and JavaScript each have their own advantages, and the choice depends on project needs and personal preferences. 1. Python is easy to learn, with concise syntax, suitable for data science and back-end development, but has a slow execution speed. 2. JavaScript is everywhere in front-end development and has strong asynchronous programming capabilities. Node.js makes it suitable for full-stack development, but the syntax may be complex and error-prone.

JavaScriptisnotbuiltonCorC ;it'saninterpretedlanguagethatrunsonenginesoftenwritteninC .1)JavaScriptwasdesignedasalightweight,interpretedlanguageforwebbrowsers.2)EnginesevolvedfromsimpleinterpreterstoJITcompilers,typicallyinC ,improvingperformance.

JavaScript can be used for front-end and back-end development. The front-end enhances the user experience through DOM operations, and the back-end handles server tasks through Node.js. 1. Front-end example: Change the content of the web page text. 2. Backend example: Create a Node.js server.

Choosing Python or JavaScript should be based on career development, learning curve and ecosystem: 1) Career development: Python is suitable for data science and back-end development, while JavaScript is suitable for front-end and full-stack development. 2) Learning curve: Python syntax is concise and suitable for beginners; JavaScript syntax is flexible. 3) Ecosystem: Python has rich scientific computing libraries, and JavaScript has a powerful front-end framework.

The power of the JavaScript framework lies in simplifying development, improving user experience and application performance. When choosing a framework, consider: 1. Project size and complexity, 2. Team experience, 3. Ecosystem and community support.


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

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 Chinese version
Chinese version, very easy to use

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.

Dreamweaver Mac version
Visual web development tools
