0

I'm creating a web application that should be responsive. In order to visualize it a bit more, I'm currently recreating the OfficeUI ribbon as Microsoft use in their products, but then for web applications.

In the ribbon, when you have all the tabs on the screen, you see something like:

enter image description here

Now, when you resize the window so that all the tabs aren't visible anymore, you see the following:

enter image description here

You can clearly see the difference, it's a button on the right side for navigating over all the various tabs.

Now, the button will be always placed on the website, but just hidden, and through some JavaScript function, I'll make it visible.

But right now, how need to know at which point I need to make the button visible.

Assume the following simple unordered list:

<ul>
    <li>Tab 1</li>
    <li>Tab 2</li>
    <li>Tab 3</li>
    <li>Tab 1</li>
    <li>Tab 2</li>
    <li>Tab 3</li>
<ul>

All the LI elements are placed next to eachother, just as in the provided images, and if I resize the window to a width that all the LI elements doesn't fit the container, then the next element is pushed down. I know this can be solved with overflow and white-space but that isn't the question here.

I need a JavaScript function to execute a function only and only when the 6 LI elements doesn't fit their container anymore.

Here's a fiddle to give it a try.

I hope that anyone can give me some guidance.

Complexity
  • 5,682
  • 6
  • 41
  • 84
  • But that is exactely the problem. The LI doesn't have a fixed width because the content is dynamic. – Complexity Mar 05 '15 at 10:52
  • Then calculate the width of the
      element on page load and save it to a global variable. Then on resize, compare the window width to the global variable - if the window width is less than or equal to the global variable, trigger your function.
    – sideroxylon Mar 05 '15 at 10:55
  • You can use @media queries to solve this too.. –  Mar 05 '15 at 10:58
  • Media css queries are probably what you're looking for.. But I personally would rather recommend you to use bootstrap for such cases, it was built for responsive design, which is most likely what you're looking for, and a navbar with your own style is the most responsive solution for such a case, in my opinion. – briosheje Mar 05 '15 at 11:01
  • @KenFyrstenberg I'm highly intrested on how to solve this with media queries. Please not that I don't know the width of the UL element before. Can you give an example on how to solve it using media queries? – Complexity Mar 05 '15 at 11:01
  • @KenFyrstenberg How would media queries help you in determining that the list items overflow the list itself? Can't see a solution here. – maryisdead Mar 05 '15 at 11:03
  • My first thought was media queries, but I can't think how to do it unless you know beforehand the widths of all the `
  • ` ... and as you say above, the `
  • `s have different widths. I hope someone can do it - will be interesting to see how. Meanwhile i tweaked your fiddle along the lines of sideroxylon's suggestion - https://jsfiddle.net/hhtjrL59/2/
  • – sifriday Mar 05 '15 at 11:05
  • ...ref http://stackoverflow.com/questions/16080961/dynamic-media-queries the answer is perhaps a media query built with JS. Answer suggested below along these lines. – sifriday Mar 05 '15 at 11:08