-
Notifications
You must be signed in to change notification settings - Fork 4
Mouse event for canvas #60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
--- | ||
title: "Canvas mouse event" | ||
weight: 80 | ||
ie_support: true | ||
--- | ||
|
||
Use this snippet to click on an area wihtin a canvas element. | ||
taupenot-autify marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Replace the values in the code as needed. | ||
|
||
|
||
```js | ||
// Replace this with your desired CSS selector | ||
var selector = "Selector here"; | ||
|
||
// Find the element | ||
var element = document.querySelector(selector); | ||
|
||
if (!element) { | ||
throw new Error("Error: cannot find the element with selector (" + selector + ")."); | ||
} | ||
|
||
// Get the element's position and size | ||
var rect = element.getBoundingClientRect(); | ||
|
||
// Change this to the xy click coordinates you need to target | ||
var clickX = rect.left + rect.width / 4; | ||
var clickY = rect.top + rect.height / 4; | ||
|
||
// List of mouse events to dispatch | ||
// Remove the mouse eventst that are not relavent | ||
taupenot-autify marked this conversation as resolved.
Show resolved
Hide resolved
|
||
var mouseEvents = ['mouseover', 'mouseenter', 'mousedown', 'mouseup', 'click', 'dblclick', 'mouseout']; | ||
|
||
// Dispatch each event | ||
mouseEvents.forEach(function(eventType) { | ||
var event = new MouseEvent(eventType, { | ||
bubbles: true, | ||
cancelable: true, | ||
clientX: clickX, | ||
clientY: clickY | ||
}); | ||
|
||
element.dispatchEvent(event); | ||
}); | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
--- | ||
title: "キャンバスのマウスイベント" | ||
weight: 80 | ||
ie_support: true | ||
--- | ||
|
||
このスニペットを使用して、`canvas` 要素内の特定の領域をクリックできます。 | ||
|
||
必要に応じてコード内の値を変更してください。 | ||
|
||
|
||
```js | ||
// 使用したい CSS セレクターをここに指定します | ||
var selector = "Selector here"; | ||
|
||
// 要素を取得 | ||
var element = document.querySelector(selector); | ||
|
||
if (!element) { | ||
throw new Error("Error: cannot find the element with selector (" + selector + ")."); | ||
} | ||
|
||
// 要素の位置とサイズを取得 | ||
var rect = element.getBoundingClientRect(); | ||
|
||
// 対象としたいクリック位置の座標を指定(ここでは要素の1/4の位置) | ||
var clickX = rect.left + rect.width / 4; | ||
var clickY = rect.top + rect.height / 4; | ||
|
||
// 発火させるマウスイベントの一覧 | ||
// 不要なマウスイベントは削除してください | ||
var mouseEvents = ['mouseover', 'mouseenter', 'mousedown', 'mouseup', 'click', 'dblclick', 'mouseout']; | ||
|
||
// 各イベントを順に発火させる | ||
mouseEvents.forEach(function(eventType) { | ||
var event = new MouseEvent(eventType, { | ||
bubbles: true, | ||
cancelable: true, | ||
clientX: clickX, | ||
clientY: clickY | ||
}); | ||
|
||
element.dispatchEvent(event); | ||
}); | ||
``` |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this file expected in the PR?