Element touching another element JavaScript [duplicate] - javascript

This question already has answers here:
Can you tell if one element is touching another using JavaScript?
(2 answers)
Closed 1 year ago.
How can I see if an element is touching another in JavaScript? I am a beginner so I was looking for something simple that doesn't require a lot of coding.

Have a look at Element.getBoundingClientRect() which will give you a bounding box including x, y, width, height, …. If it's rectangular elements, then you can simply check if they intersect.

Related

Paper JS detect closed path

Paper JS reference has boolean math operations which checks one object against another object.
Problem is I see it's not enough to accomplish what I need which is to detect a closed path whether it be self-intersecting or two or more objects intersecting each other.
As a reference on below image, i cannot find a solution for the first two at the top. The image below which has the green fill works fine since the path is connected to the first mouse-down point.

how to make layers in js [duplicate]

This question already has answers here:
Three.js - Geometry on top of another
(4 answers)
Closed 6 years ago.
Is there a way in js to set something like layers?
I want some objects in my canvas to no matter what - be rendered on top of everything, and some to be rendered behind everything, regardless of their real position in the scene.
Is it possible?
what is the way to do that?
Thanks
One method is to use multiple scenes. Set renderer.autoClear=false, then to render, something along the lines of:
renderer.clear();
renderer.render(bottomLayer, camera);
renderer.clearDepth();
renderer.render(topLayer, camera);
That wouldn't be suitable in some cases. If not, then you might look into the object renderOrder and material polygonOffset properties.

Force the browser to use actual '\n' when it line breaks [duplicate]

This question already has answers here:
Finding line-wraps
(6 answers)
Closed 6 years ago.
I have an areatext box, and when a line gets too long, it wraps onto the next line. However, it does so without inserting a newline character into the text, and I need that newline character, so that the element.scrollHeight gets changed.
I can think of ways to do this in javascript, for example by taking the font-size along with the number of characters and insert \n appropriately, however I hope there is a simpler solution, maybe just a simple css setting?
EDIT:
Example:https://jsfiddle.net/ah126wm5/1/
There is no CSS to inject a line break like that, you'll need script.
The reason is that a text that does not get line breaks manually, is supposed to adjust to its container width and that's why it behaves like that.
Side note: The textarea's scroll height still reports correct as you can see in this updated fiddle, just add more text and check the height and you'll see it works

Create custom connection [duplicate]

This question already has an answer here:
How do I create image connecting two vertices in mxGraph?
(1 answer)
Closed 9 years ago.
I want to create a specific connection between two nodes. The connection would have an image. Is this possible?
I work with mxGraph, javascript.
http://upload.wikimedia.org/wikipedia/commons/0/08/Simple_stock_and_flow_diagram.gif
Sorry, for my english. Thanks.
You'll need to (and I'm looking at the v2 API here) create your own edge shape, most likely based on mxConnector (in the shape folder). paintEdgeShape defines the rendering of the edge, you use the canvas API to define that drawing (see API specifications for mxAbstractCanvas2D).

Is there a way to identify an element on the page at a specified location in javascript? [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
How do I find the DOM node that is at a given (X,Y) position? (Hit test)
I'm looking to identify the target DOM element at a specified location. For example, I want to say, give me the element at offset 200px from the top and 150px from the left. This needs to be done programatically, and not via an event (for example, it should be able to return the element when the page loads)
For extra points, would it be possible to identify a word or string of words at a specified location?
Is there an easy way to do this using jQuery?
Target: I would like to dynamically insert a div into this location and float it right.
(This is a duplicate of How do I find the DOM node that is at a given (X,Y) position? (Hit test))
document.elementFromPoint()
See the Firefox reference at
https://developer.mozilla.org/En/DOM:document.elementFromPoint
and cross-browser issues at
http://www.quirksmode.org/blog/archives/2010/06/more_ie9_goodne.html
There is nothing built into JavaScript that gets an element by position. Only way to identify elements by posiition would be to map every element on the page with its x,y,z position and figure out what is at the point. Possible, but performance would probably be bad.

Categories