<!-- /////////////////////////////////////////////////////////////////////////////////////////// -... --> <!-- --> <div id=selectBox> <!-- , , div- --> <img src="arrow.png" alt="" width='15px' class=arrow /> <!-- , --> <p class=valueTag name=select></p> <!-- --> <ul id=selectMenuBox> <li class=option></li> <li class=option></li> <li class=option></li> <li class=option></li> <li class=option></li> <li class=option></li> <li class=option></li> <li class=option></li> <li class=option></li> <li class=option></li> <li class=option></li> <li class=option></li> </ul> </div> <!-- --> </body> </html>
div#selectBox { width: 250px; position: relative; height: 50px; border-radius: 3px; border: solid 1px lightgrey; background-color: #fff; color: #333; cursor: pointer; overflow: hidden; transition: .3s; } div#selectBox p.valueTag { padding: 15px; cursor: pointer; transition: .2s; height: 40px; } div#selectBox > img.arrow { position: absolute; right: 0; width: 50px; padding: 15px; } /* Safari, Chrome Opera — -. */ ::-webkit-scrollbar { background: transparent; width: 0.5em; position: absolute; } ::-webkit-scrollbar-track { background: transparent; position: absolute; z-index: -2; } ::-webkit-scrollbar-thumb { border-radius: 100px; background: #888; } ul#selectMenuBox { background: #fff; transition: .3s; width: 100%; height: 200px; overflow-y: auto; overflow-x: hidden !important; position: absolute; margin-top: 00px; display: block; } ul#selectMenuBox > li { display: block; padding: 10px; border-radius: 00px; cursor: pointer; } ul#selectMenuBox > li.option { color: gray; padding: 10px; } ul#selectMenuBox > li.option:hover { color: #333; background: #e1e1e1; transition: .2s; }
(function( $ ) { $.fn.selectbox = function() { // // div'a. var selectDefaultHeight = $('#selectBox').height(); // div'e var rotateDefault = "rotate(0deg)"; // , // div'a. // (, ) $('#selectBox > p.valueTag').click(function() { // height() var currentHeight = $('#selectBox').height(); // / , // . . if (currentHeight < 100 || currentHeight == selectDefaultHeight) { // , , // . $('#selectBox').height("250px"); // « » // CSS3 $('img.arrow').css({borderRadius: "1000px", transition: ".2s", transform: "rotate(180deg)"}); } // ( 250 ), // valueTag, // + if (currentHeight >= 250) { $('#selectBox').height(selectDefaultHeight); $('img.arrow').css({transform: rotateDefault}); } }); // // $('li.option').click(function() { $('#selectBox').height(selectDefaultHeight); $('img.arrow').css({transform: rotateDefault}); $('p.valueTag').text($(this).text()); }); }; })( jQuery );
$('selector').selectbox();
Source: https://habr.com/ru/post/312532/
All Articles