Created
June 20, 2013 09:14
-
-
Save Phonbopit/5821390 to your computer and use it in GitHub Desktop.
สร้าง drop-down Menu ด้วย jQuery Step-by-Step
@see http://devsharing.com/2013/javascript/jquery/create-drop-down-menu-jquery-step-by-step/
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
<div class="leftmenu"> | |
</div> |
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> | |
<li class ="menu" id="programming" >Programming </li> | |
<li class ="menu" id="category" >Web Programming </li> | |
<li class ="menu" id="os" >OS</li> | |
</ul> |
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> | |
<!-- Programming --> | |
<li class ="menu" id="programming" >Programming </li> | |
<ul> | |
<li class="submenu"><a href="#" title="Java" > Java </a></li> | |
<li class="submenu"><a href="#" title="C++" > C++ </a></li> | |
<li class="submenu"><a href="#" title="Objective-C" > Objective-C</a></li> | |
</ul> | |
<!-- Web Programming --> | |
<li class ="menu" id="category" >Web Programming </li> | |
<ul> | |
<li class="submenu"><a href="#" title="HTML" > HTML </a></li> | |
<li class="submenu"><a href="#" title="CSS" > CSS </a></li> | |
<li class="submenu"><a href="#" title="javascript" > javascript</a></li> | |
</ul> | |
<!-- OS --> | |
<li class ="menu" id="os" >OS</li> | |
<ul> | |
<li class="submenu"><a href="#" title="Ubuntu" >Ubuntu </a></li> | |
<li class="submenu"><a href="#" title="Windows" >Windows </a></li> | |
<li class="submenu"><a href="#" title="Mac OS" >Mac OS </a></li> | |
</ul> | |
</ul> |
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
<script type="text/javascript"></script> |
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
<script type="text/javascript" src="script.js"></script> |
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
jQuery(document).ready(); หรือแบบสั้น | |
$(document).ready(); |
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
$('.leftmenu ul ul').hide(); |
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
var mainMenu = $('.menu'); | |
mainMenu.click(function() { | |
if(!$(this).hasClass('active')) { | |
$(this).next('ul').slideDown(); | |
} | |
}); |
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
if(!$(this).hasClass('active')) { | |
$(this).siblings('ul').slideUp(); | |
$(this).next('ul').slideDown(); | |
} |
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
if(!$(this).hasClass('active')) { | |
$(this).siblings('ul').slideUp(); | |
$(this).next('ul').slideDown(); | |
} |
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
if(!$(this).hasClass('active')) { | |
$(this).siblings('ul').slideUp(); | |
$(this).next('ul').slideDown(); | |
$(this).addClass('active'); | |
$(this).siblings().removeClass('active'); | |
} |
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
else { | |
$(this).removeClass('active'); | |
$(this).next().stop(true,true).slideUp(); | |
} |
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
.leftmenu { | |
width: 30%; | |
padding-bottom: 15px; | |
text-align: center; | |
margin-right: 5px; | |
} | |
.menu { | |
color:#fff; | |
background-color:#000; | |
list-style:none; | |
margin: 5px 0px; | |
padding:5px; | |
border: 2px solid #000; | |
border-radius: 15px; | |
} | |
.menu:hover { | |
color:#000; | |
background-color:#fff; | |
cursor: pointer; | |
} | |
.submenu { | |
list-style:none; | |
background-color: #c8c8c8; | |
margin: 3px 0px; | |
padding:3px; | |
border : 2px solid #000; | |
border-radius:15px; | |
} |
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
<div class="leftmenu"> | |
<ul> | |
<!-- Programming --> | |
<li class ="menu" id="programming" >Programming </li> | |
<ul> | |
<li class="submenu"><a href="#" title="Java" > Java</a></li> | |
<li class="submenu"><a href="#" title="C++" > C++</a></li> | |
<li class="submenu"><a href="#" title="Objective-C" > Objective-C</a></li> | |
</ul> | |
<!-- Web Programming --> | |
<li class ="menu" id="category" >Web Programming </li> | |
<ul> | |
<li class="submenu"><a href="#" title="HTML" > HTML</a></li> | |
<li class="submenu"><a href="#" title="CSS" > CSS</a></li> | |
<li class="submenu"><a href="#" title="javascript" > javascript</a></li> | |
</ul> | |
<!-- OS --> | |
<li class ="menu" id="os" >OS</li> | |
<ul> | |
<li class="submenu"><a href="#" title="Ubuntu" >Ubuntu</a></li> | |
<li class="submenu"><a href="#" title="Windows" >Windows</a></li> | |
<li class="submenu"><a href="#" title="Mac OS" >Mac OS</a></li> | |
</ul> | |
</ul> | |
</div> |
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
jQuery(document).ready(function() { | |
$('.leftmenu ul ul').hide(); | |
var mainMenu = $('.menu'); | |
mainMenu.click(function() { | |
if(!$(this).hasClass('active')) { | |
$(this).siblings('ul').slideUp(); | |
$(this).next('ul').slideDown(); | |
$(this).addClass('active'); | |
$(this).siblings().removeClass('active'); | |
} else { | |
$(this).removeClass('active'); | |
$(this).next().stop(true,true).slideUp(); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment