Created
February 19, 2013 05:19
-
-
Save ikawka/4983300 to your computer and use it in GitHub Desktop.
Simi-static Menu with JQuery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ul class="shown"> | |
<li>A</li> | |
<li>B</li> | |
<li>C</li> | |
<li>D</li> | |
</ul> | |
<ul class="hidden"> | |
<li class="more">...</li> | |
</ul> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
li { | |
position:relative; | |
font-size:30px; | |
width:30px; | |
padding:35px; | |
background-color:#dddddd; | |
margin:5px; | |
} | |
ul.hidden li { | |
float:left; | |
cursor:pointer; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('.hidden').hover(function(){ | |
$(this).children(':not(.more)').show() | |
}, function(){ | |
$(this).children(':not(.more)').hide() | |
}) | |
$(window).resize(function(){ | |
var newHeight = $(window).height() | |
var listHeight = $('ul.shown').height() | |
var hiddenList = $('ul.hidden') | |
var shownList = $('ul.shown') | |
if(newHeight < (listHeight+100)){ | |
var elementToHide = $('ul.shown li').last() | |
hiddenList.append(elementToHide) | |
elementToHide.hide() | |
}else if(newHeight >= (listHeight+200)){ | |
var elementToShow = $('ul.hidden li:not(.more)').first() | |
shownList.append(elementToShow) | |
elementToShow.show() | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment