250x250
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- express.js
- Ethereum
- bitcoin
- JavaScript
- useState
- HTML
- 삶
- Props
- blockchain
- SSR
- built in object
- nextJS
- evm
- web
- concept
- Interface
- typeScript
- hardhat
- Redux
- 기준
- CSS
- tailwindcss
- CLASS
- node.js
- solidity
- graphQL
- error
- REACT
- middleware
- API
Archives
- Today
- Total
ReasonJun
javascript : event (mouse pointer event, prevent basic work) 본문
Frontend/Javasciprt
javascript : event (mouse pointer event, prevent basic work)
ReasonJun 2023. 6. 9. 00:10728x90
mouse pointer event
// Mouse & Pointer Events
// click
// dbclick : double click
// mousedown : press the button
// mouseup : release the button
// mouseenter : When the pointer goes over an element
// mouseleave : when the pointer goes out of the element
// mousemove : when the pointer moves
// contextmenu : when right-clicked
// wheel :When the wheel button rotates
const parentEl = document.querySelector('.parent');
const childEl = document.querySelector('.child');
childEl.addEventListener('click', () => {
childEl.classList.toggle('active');
});
childEl.addEventListener('dbclick', () => {
childEl.classList.toggle('active');
});
//!
childEl.addEventListener('mousedown', () => {
childEl.classList.add('active');
});
childEl.addEventListener('mouseup', () => {
childEl.classList.remove('active');
});
//!
childEl.addEventListener('mouseenter', () => {
childEl.classList.add('active');
});
childEl.addEventListener('mouseleave', () => {
childEl.classList.remove('active');
});
//! mouse position tracking
childEl.addEventListener('mousemove', (event) => {
console.log(event.offsetX, event.offsetY);
});
//! right mouse click
childEl.addEventListener('contextmenu', (event) => {
event.preventDefault(); // Removes the event that appears on right-click.
console.log(event);
});
//! When scrolling up, delta Y is negative and the opposite is positive
childEl.addEventListener('wheel', (event) => {
console.log(event);
});
prevent basic work
// Prevent mouse wheel from scrolling
const parentEl = document.querySelector('.parent');
parentEl.addEventListener('wheel', (event) => {
event.preventDefault(); // It does not block the event, but only the basic behavior of the browser.
console.log('wheel'); // Then this part works fine.
});
// <a> Prevent page shifting in tags
const anchorEl = document.querySelector('a');
anchorEl.addEventListener('click', (event) => {
event.preventDefault();
console.log('click');
});
728x90
'Frontend > Javasciprt' 카테고리의 다른 글
javascript : map (0) | 2023.06.09 |
---|---|
javascript : set (0) | 2023.06.09 |
javascript : event (handler once, passive, keyboard) (0) | 2023.06.09 |
javascript : event (event obj, focus form event) (0) | 2023.06.09 |
javascript : event (delegation, event bubbling) (0) | 2023.06.08 |
Comments