Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I make all of the position attributes the same?
    primarykey
    data
    text
    <p>I made a drag-and-drop engine in JavaScript, and I'm currently adding a "bounding" feature. My issue is that the bounding element's position changes depending on its parent's <code>position:</code> attribute.</p> <p>In other words this html:</p> <pre><code>&lt;div id="center" class="bound"&gt; &lt;h1&gt;Hello World! &lt;hr /&gt;&lt;/h1&gt; &lt;div id="box" class="bound"&gt; &lt;p class="drag square" id="one"&gt; One &lt;/p&gt; &lt;p class="drag square" id="two"&gt; Two &lt;/p&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>and this html:</p> <pre><code>&lt;div id="center"&gt; &lt;!-- Difference is here --&gt; &lt;h1&gt;Hello World! &lt;hr /&gt;&lt;/h1&gt; &lt;div id="box" class="bound"&gt; &lt;p class="drag square" id="one"&gt; One &lt;/p&gt; &lt;p class="drag square" id="two"&gt; Two &lt;/p&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>affect the engine in different ways, and they shouldn't. Only the <code>&lt;div id="box" class="bound"&gt;</code> should affect the drag object.</p> <p>Here is the CSS:</p> <pre><code>@charset "utf-8"; /* CSS Document */ * { padding: 0px; margin: 0px; } .drag { position: absolute; -webkit-user-select: none; -moz-user-select: none; user-select: none; } .bound { position: relative; } .square { width: 100px; height: 100px; background: red; cursor:move; } #center { width: 500px; height: 300px; margin: auto; margin-top: 50px; background-color:#ccc; text-align: center; border-radius: 25px; -moz-border-radius: 25px; } #box { background-color: #FF3; height: 278px; border-radius: 0 0 25px 25px; -moz-border-radius: 0 0 25px 25px; opacity: 0.5; } </code></pre> <p>If anyone asks for the JavaScript function which sets the bounding, I will be happy to post it in an edit!</p> <p><strong>To make the position attribute not affect my JavaScript would I need to translate everything into absolute coordinates? How would I do this? Will translating everything into absolute coordinates allow the JavaScript to treat the two html samples the same way?</strong></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload