Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've also taken the same JS codes, and adapted it to my website (still under construction). Here's some of the codes (working)</p> <h2>HTML</h2> <pre><code>&lt;div class="fix_on_top"&gt; &lt;div class="container"&gt; &lt;ul class="breadcrumb"&gt; &lt;li&gt;&lt;a href="#"&gt;Home&lt;/a&gt; &lt;span class="divider"&gt;/&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;Packages&lt;/a&gt; &lt;span class="divider"&gt;/&lt;/span&gt;&lt;/li&gt; &lt;li class="active"&gt;Professional courses - I am a breadcrumb; I'll fix myself below the top navbar when you scroll the page&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <h2>LESS (CSS)</h2> <pre><code>.fixed_on_top { left: 0; right: 0; z-index: 1020; position: fixed; top:$navbarHeight; } </code></pre> <h2>JavaScript</h2> <pre><code>var $window = $(window), $fix_on_top = $('.fix_on_top'), fixed_Top = $('.fix_on_top').length &amp;&amp; $('.fix_on_top').offset().top - 40, isFixed = 0; process_scroll(); // hack sad times - holdover until rewrite for 2.1 $fix_on_top.on('click', function () { if (!isFixed) setTimeout(function () { $window.scrollTop($window.scrollTop() - 47) }, 10); }); $window.on('scroll', process_scroll); function process_scroll() { var i, scrollTop = $window.scrollTop(); if (scrollTop &gt;= fixed_Top &amp;&amp; !isFixed) { isFixed = 1; $fix_on_top.addClass('fixed_on_top'); } else if (scrollTop &lt;= fixed_Top &amp;&amp; isFixed) { isFixed = 0; $fix_on_top.removeClass('fixed_on_top'); } } </code></pre> <p>I've also adapted the original code (for another website) that works on THEAD (tables - i have one table per webpage with id = "tablesortable")</p> <pre><code>// Automatically add the class "fix_on_scroll" on #tablesortable's thead if ($('#tablesortable thead').length) { var thead_cells = new Array(); $('#tablesortable thead').addClass('fix_on_scroll'); // Get the width of each cells in thead $('#tablesortable thead').find('td, th').each(function(i, v) { thead_cells.push($(this).width()); }); // Keep same with in tbody and tfoot $('#tablesortable tbody tr:first').children('td, th').each(function(i, v) { $(this).width(thead_cells[i]); }); $('#tablesortable tfoot tr:first').children('td, th').each(function(i, v) { $(this).width(thead_cells[i]); }); } // Fix all elements (with class .fix_on_scroll) just below the top menu on scroll // (Modified version from homepage of Twitter's Bootstrap - js/application.js) var $window = $(window), $fix_on_scroll = $('.fix_on_scroll'), fixed_elem_top = $('.fix_on_scroll').length &amp;&amp; $('.fix_on_scroll').offset().top - 26, isFixed = 0; process_scroll(); // hack sad times - holdover until rewrite for 2.1 $fix_on_scroll.on('click', function () { if (!isFixed) setTimeout(function () {$window.scrollTop($window.scrollTop() - 40)}, 10) }); $window.on('scroll', process_scroll); function process_scroll() { var i, scrollTop = $window.scrollTop(); if (scrollTop &gt;= fixed_elem_top &amp;&amp; !isFixed) { isFixed = 1; $fix_on_scroll.addClass('fixed_on_scroll'); // Keep original width of td/th if ($fix_on_scroll.is('thead')) { $fix_on_scroll.find('td, th').each(function(i, v) { $(this).width(thead_cells[i]); }); } } else if (scrollTop &lt;= fixed_elem_top &amp;&amp; isFixed) { isFixed = 0 $fix_on_scroll.removeClass('fixed_on_scroll') } } </code></pre> <p>My (adapted) codes are working. You can use them.</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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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