Note that there are some explanatory texts on larger screens.

plurals
  1. POCounting <ul> height with Javascript
    primarykey
    data
    text
    <p>Here's my situation. I have a sliding jquery menu like this: <a href="http://tympanus.net/codrops/2011/07/03/sliding-background-image-menu" rel="nofollow">http://tympanus.net/codrops/2011/07/03/sliding-background-image-menu</a>.</p> <p>The code of menu is:</p> <pre><code>&lt;div id="sbi_container" class="sbi_container"&gt; &lt;div class="sbi_panel" data-bg="images/1.jpg"&gt; &lt;a href="#" class="sbi_label"&gt;About&lt;/a&gt; &lt;div class="sbi_content"&gt; &lt;ul&gt; &lt;li&gt;&lt;a href="#"&gt;Subitem&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;Subitem&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;Subitem&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="sbi_panel" data-bg="images/2.jpg"&gt; ... &lt;/div&gt; </code></pre> <p>CSS:</p> <pre><code>.sbi_content{ position:absolute; border-top:2px solid #000; bottom:90px; left:0px; width:100%; background:transparent url(../images/pattern.png) repeat top left; display:none; overflow:hidden; } .sbi_content ul{ padding:10px; } .sbi_content ul a{ display:block; color:#f0f0f0; font-size:16px; padding:4px 6px 4px 14px; background:transparent url(../images/triangle.png) no-repeat 3px 50%; opacity:0.9; } .sbi_content ul a:hover{ background-color:#000; color:#fff; -moz-box-shadow:1px 1px 5px #000; -webkit-box-shadow:1px 1px 5px #000; box-shadow:1px 1px 5px #000; } </code></pre> <p>And here's a JavaScript piece I have a problem with: </p> <pre><code> $content.each(function(i) { var $el = $(this); // save each content's height (where the menu items are) // and hide them by setting the height to 0px var num = $el.find('ul li').size(); $el.data( 'height', num * 35 + 10 ).css( 'height', '0px' ).show(); }); </code></pre> <p>I need to count a height of these <code>&lt;ul&gt;</code>. That I'm doing now is counting how many there are <code>&lt;li&gt;</code> items, then multiply it by number of one's height (35) and adding a 10px for margin..</p> <p>Everything would be ok, but when there is a realy long <code>&lt;li&gt;</code> item, it jumps to second row and problem is that this code doesn't count that second row height.</p> <p>Any ideas how can I solve this problem?</p> <p>Thank you.</p>
    singulars
    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