How to detect the center line of a canvas to center an object when it has dragge...
source link: https://www.codesd.com/item/how-to-detect-the-center-line-of-a-canvas-to-center-an-object-when-it-has-dragged.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
How to detect the center line of a canvas to center an object when it has dragged?
This question belongs to fabricJS and canvas.When I dragged a object to a canvas I need to detect center line and snap to it. I found some similar approach in this question. But it deals with div
elements. I need to deal with center line of the canvas. How I do this?
You can define snap functionality manually with moving
option. Try following.
'object:moving' : function(e){
var objCenter = e.target.getLeft() + (e.target.getWidth()/2);
var targetLine = canvas.left+(canvas.width/2);
if(objCenter > targetLine-10 && objCenter < targetLine+10){
e.target.left = targetLine - (e.target.getWidth()/2) ;
}else{
e.target.setOpacity(1);
}
Related Articles
How to detect the last line in awk before END
how to detect the third line before a certain line
c # How to detect if a line (painted / drawn on a form) was clicked when using winforms?
How to detect the center of a fuzzy circle with opencv
Flexible container, how to justify the center, but aligned when no space for margin
How to detect the Sun from the sky of space in OpenCv?
How to detect the modification of the entry when it has changed dynamically
How to detect the character encoding of a Web page programmatically?
How to match the request line using regex?
How to detect the empty table when selecting a row in a jQuery Datatable
How to print the following line from PHP
How to change the separator line color for a single table section?
How to detect the client country, location in laravel 4
How to detect the row of the cell that has been touched
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK