鼠标事件问题
See more on JavaScript events
进一步了解JavaScript事件
When looking at mouse events we have the ability to interact with
在查看鼠标事件时,我们可以与之交互
mousedownthe mouse button was pressedmousedown鼠标按钮mouseupthe mouse button was releasedmouseup释放了鼠标按钮clicka click eventclick点击事件dblclicka double click eventdblclick双击事件mousemovewhen the mouse is moved over the element将鼠标移到元素上时
mousemovemouseoverwhen the mouse is moved over an element or one of its child elements将鼠标移到一个元素或其子元素之一上时的
mouseovermouseenterwhen the mouse is moved over an element. Similar tomouseoverbut does not bubble (more on this soon!)将鼠标移到元素上时的
mouseenter。 与mouseover类似,但不会冒泡(稍后会更多!)mouseoutwhen the mouse is moved out of an element, and when the mouse enters a child elements将鼠标移出元素时,以及进入子元素时的
mouseoutmouseleavewhen the mouse is moved out of an element. Similar tomouseoutbut does not bubble (more on this soon!)将鼠标移出元素时的
mouseleave。 与mouseout类似,但不会冒泡(稍后会更多!)contextmenuwhen the context menu is opened, e.g. on a right mouse button clickcontextmenu时上下文菜单打开时,如在点击鼠标右键
Events overlap. When you track a click event, it’s like tracking a mousedown followed by a mouseup event. In the case of dblclick, click is also fired two times.
事件重叠。 跟踪click事件时,就像跟踪mousedown事件和mouseup事件一样。 在dblclick的情况下, click也被触发两次。
mousedown, mousemove and mouseup can be used in combination to track drag-and-drop events.
mousedown , mousemove和mouseup可以组合使用来跟踪拖放事件。
Be careful with mousemove, as it fires many times during the mouse movement. We need to apply throttling, which is something we’ll talk more when we’ll analyze scrolling.
小心mousemove ,因为它在鼠标移动期间会触发多次。 我们需要应用节流 ,这是我们在分析滚动时将要讨论的更多内容。
When inside an eventh handler we have access to lots of properties.
在一个偶数处理程序中,我们可以访问许多属性。
For example on a mouse event we can check which mouse button was pressed by checking the button property of the event object:
例如,在鼠标事件中,我们可以通过检查事件对象的button属性来检查按下了哪个鼠标按钮:
const link = document.getElementById('my-link')
link.addEventListener('mousedown', event => {
// mouse button pressed
console.log(event.button) //0=left, 2=right
})
Here are all the properties we can use:
这是我们可以使用的所有属性:
altKeytrue if alt key was pressed when the event was firedaltKey如果触发事件时按下alt键,altKeytruebuttonif any, the number of the button that was pressed when the mouse event was fired (usually 0 = main button, 1 = middle button, 2 = right button). Works on events caused by clicking the button (e.g. clicks)如果有
button则为触发鼠标事件时按下的按钮编号(通常为0 =主按钮,1 =中间按钮,2 =右键)。 对通过单击按钮引起的事件起作用(例如,单击)buttonsif any, a number indicating the button(s) pressed on any mouse event.buttons如果有),数字表示在任何鼠标事件中按下的按钮。clientX/clientYthe x and y coordinates of the mouse pointer relative to the browser window, regardless of scrollingclientX/clientY鼠标指针相对于浏览器窗口的x和y坐标,与滚动无关ctrlKeytrue if ctrl key was pressed when the event was firedctrlKey如果触发事件时按下ctrl键,则为truemetaKeytrue if meta key was pressed when the event was firedmetaKey如果触发事件时按下了meta键,metaKeytruemovementX/movementYthe x and y coordinates of the mouse pointer relative to the position of the last mousemove event. Used to track the mouse velocity while moving it aroundmovementX/movementYx和相对于最后mousemove事件的位置的鼠标指针的y坐标。 用于在移动鼠标时跟踪鼠标速度regionused in the Canvas APICanvas API中使用的
regionrelatedTargetthe secondary target for the event, for example when movingrelatedTarget事件的次要目标,例如在移动时screenX/screenYthe x and y coordinates of the mouse pointer in the screen coordinatesscreenX/screenY屏幕坐标中鼠标指针的x和y坐标shiftKeytrue if shift key was pressed when the event was firedshiftKey如果触发事件时按下Shift键,则为true
翻译自: https://flaviocopes.com/mouse-events/
鼠标事件问题
最后
以上就是贤惠百褶裙最近收集整理的关于鼠标事件问题_鼠标事件的全部内容,更多相关鼠标事件问题_鼠标事件内容请搜索靠谱客的其他文章。
发表评论 取消回复