LOADING...

Preview

Pen ID
Unlock Campus Themeforest adv

 

Code

Users

CSS
@charset "UTF-8";
/* OPTIONS */
* {
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}

body {
  font-family: 'Lato', sans-serif;
  background-color: #fff;
  color: #A2ACB0;
}

/* STYLES */
section {
  width: 300px;
  display: block;
  margin: 50px auto;
  text-align: center;
}

h1 {
  font-size: 36px;
  font-weight: 300;
  color: #343C3F;
  margin-bottom: 1em;
}

.dropdown {
  text-align: left;
  color: #343C3F;
  border: 1px solid #A2ACB0;
}
.dropdown.closed .dropdown-menu {
  margin-top: 0px;
}
.dropdown.closed .dropdown-menu li {
  height: 0px;
}
.dropdown.closed .title {
  border-bottom: none;
}
.dropdown.closed .title:after {
  margin-top: -16px;
  -webkit-transform: rotate(0deg);
  -moz-transform: rotate(0deg);
  -ms-transform: rotate(0deg);
  -o-transform: rotate(0deg);
  transform: rotate(0deg);
}
.dropdown .title {
  width: 100%;
  position: relative;
  height: 40px;
  padding: 12px;
  cursor: pointer;
  border-bottom: 1px solid #D9E1E4;
}
.dropdown .title:after {
  display: block;
  content: "▾";
  position: absolute;
  right: 14px;
  margin-top: -16px;
  -webkit-transform: rotate(180deg);
  -moz-transform: rotate(180deg);
  -ms-transform: rotate(180deg);
  -o-transform: rotate(180deg);
  transform: rotate(180deg);
}
.dropdown .dropdown-menu {
  position: relative;
  overflow: hidden;
  max-height: 200px;
  -webkit-transition: all 0.2s;
  -moz-transition: all 0.2s;
  transition: all 0.2s;
  -webkit-box-sizing: "border-box";
  -moz-box-sizing: "border-box";
  box-sizing: "border-box";
}
.dropdown ul {
  position: absolute;
  top: 0;
  width: 100%;
}
.dropdown ul li {
  width: 100%;
  height: 40px;
  line-height: 40px;
  border-bottom: 1px solid #D9E1E4;
  padding: 0 12px;
  vertical-align: top;
  overflow: hidden;
  cursor: pointer;
  -webkit-transition: margin-top 0.5s, height 0.5s;
  -moz-transition: margin-top 0.5s, height 0.5s;
  transition: margin-top 0.5s, height 0.5s;
}
.dropdown ul li:hover {
  background-color: #D9E1E4;
  color: #343C3F;
}
JS
var $container = $('.dropdown-menu'),
    $list = $('.dropdown-menu ul'),
    listItem = $list.find('li');

$(".dropdown .title").click(function () {
  if( $container.height() > 0) {
    closeMenu(this);
  } else {
    openMenu(this);
  }
});

$(".dropdown-menu li").click(function () {
  closeMenu(this);
});

function closeMenu(el) {
  $(el).closest('.dropdown').toggleClass("closed").find(".title").text($(el).text());
  $container.css("height", 0);
  $list.css( "top", 0 );
}

function openMenu(el) {
  $(el).parent().toggleClass("closed");
  
  $container.css({
    height: 200
  })
  .mousemove(function(e) {
    var heightDiff = $list.height() / $container.height(),
        offset = $container.offset(),
        relativeY = (e.pageY - offset.top),
        top = relativeY*heightDiff > $list.height()-$container.height() ?
              $list.height()-$container.height() : relativeY*heightDiff;

    $list.css("top", -top);
  });
}
Host Instantly Drag and Drop Website Builder

 

Description

A dropdown with autoscroll.
Term
Mon, 11/27/2017 - 21:49

Related Codes

Pen ID
Pen ID
Pen ID