JSFiddle - React, Tailwind, and code Playground
by seler
HTML
<ul id="tricky_list">
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
<li>Item 5</li>
</ul>
JavaScript
var limit = 3;
var list = $("#tricky_list");
var more = 0;
function tricky_hide(){
var morec = 0;
$("li", list).each(function(index) {
if (index >= limit) {
$(this).hide();
morec = index - limit + 1;
}
});
if (!more) more = morec;
if (more) {
list.append('<li class="more">' + more + ' more</li>');
return true;
}
return false;
}
if (tricky_hide()) {
list.live("mouseover", function() {
$("li", list).each(function(index) {
$(this).show();
});
$("li.more", list).hide();
});
list.live("mouseout", function() {
tricky_hide();
});
}