Created
July 21, 2015 23:06
-
-
Save IGGY-MODEL/727f90800c42e89ea433 to your computer and use it in GitHub Desktop.
Custom <select> / <ul> + jQuery
This file contains hidden or 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
| <!-- HTML --> | |
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="utf-8"> | |
| <meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1"> | |
| <title>INFO 4 HIM</title> | |
| <link rel="stylesheet" href="main.css"> | |
| <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries --> | |
| <!-- WARNING: Respond.js doesn't work if you view the page via file:// --> | |
| <!--[if lt IE 9]> | |
| <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script> | |
| <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script> | |
| <![endif]--> | |
| </head> | |
| <body> | |
| <ul id="select-box"> | |
| <li id="selected">-Choose-</li> | |
| <li>First</li> | |
| <li>Second</li> | |
| <li>Third</li> | |
| <li>Fourth</li> | |
| <li>Fifth</li> | |
| </ul> | |
| <!-- jQuery --> | |
| <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script> | |
| <script src="main.js"></script> | |
| </body> | |
| </html> | |
| <!-- END HTML --> | |
| /*CSS*/ | |
| ul { | |
| list-style-type: none; | |
| padding: 0; | |
| margin: 0; | |
| text-align: center; | |
| border: 1px solid #11cccc; | |
| width: 200px; | |
| height: 28px; | |
| overflow: hidden; | |
| font-family: Helvetica; | |
| font-size: 16px; | |
| cursor: pointer; | |
| } | |
| li { | |
| display: block; | |
| background: #11dddd; | |
| color: white; | |
| padding: 5px; | |
| } | |
| li:first-child { | |
| position: relative; | |
| border-bottom: 1px solid #11cccc; | |
| } | |
| li:first-child:after { | |
| position: absolute; | |
| right: 10px; | |
| top: 11px; | |
| content: ""; | |
| display: block; | |
| border-top: 5px solid #1aa; | |
| border-left: 5px solid transparent; | |
| border-right: 5px solid transparent; | |
| } | |
| li:hover, | |
| li.selected { | |
| background: #11cccc; | |
| } | |
| /*END CSS*/ | |
| /*JS (jQuery)*/ | |
| $(document).ready(function() { | |
| var select = $('#select-box'), | |
| firstLi = $('#selected'), | |
| option = $('#select-box li'); | |
| option.on('click', function () { | |
| var that = $(this); | |
| if ( that.text() === firstLi.text() ) { | |
| select.css({'height':'168px'}); | |
| } else { | |
| firstLi.text(that.text()); | |
| that.addClass('selected').siblings().removeClass('selected'); | |
| select.css({'height':'28px'}); | |
| } | |
| return false; | |
| }); | |
| $('html,body').on('click', function(event) { | |
| event.preventDefault(); | |
| select.css({'height':'28px'}); | |
| }); | |
| }); | |
| /*END JS*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment