Note that there are some explanatory texts on larger screens.

plurals
  1. POMove elements to list when window to small to show them
    primarykey
    data
    text
    <p>I am working on a toolbar for my website and currently I have populated it with random buttons, and I want them to move to another list if the window is resized and the buttons cannot fit.</p> <p>Here is the code: </p> <pre><code>window.onresize = function() { var div = document.getElementById("button_holder"); var divRight = document.getElementById('button_holder_right'); var extraButton = document.getElementById('barMoreButton'); var extraMenu = document.getElementById('extraMenu'); var i; widthOfResizeMenuItems = 0; for (i=0;i&lt;div.childNodes.length;i++) { var button = div.childNodes[i]; if( widthOfResizeMenuItems &gt; div.offsetWidth ) { button.remove(); extraMenu.appendChild(button); extraButton.style.display = 'inline-block'; divRight.width = 78; }else if( widthOfResizeMenuItems &lt; div.offsetWidth ) { if( extraMenu.childNodes.length &gt; 0 ) { div.appendChild(extraMenu.childNodes[0]); } extraButton.style.display = 'none'; divRight.width = 52; } widthOfResizeMenuItems = widthOfResizeMenuItems + button.offsetWidth; } console.log("Count: " + i + " --- Width: " + widthOfResizeMenuItems); } </code></pre> <p>heres the bars structure</p> <pre><code>div#srgapi_toolbar table tr td#button_holder button (x9) td#button_holder_right button#barMoreButton div#extraMenu </code></pre> <p>and here is a demo: <a href="http://api.shadowravengames.co.uk/test.php" rel="nofollow">http://api.shadowravengames.co.uk/test.php</a> try resizing the window to see what is happening at the moment</p> <p>What am I doing wrong, why are the elements wrapping to a new line instead of moving to the other menu, and how can I fix it?</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.
    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