jquery 实现的select下拉列表

 

效果如下:

jquery 实现的select下拉列表_第1张图片

html 

    

css

a {
  text-decoration: none;
}

ul,
li,
ol {
  list-style: none outside none;
  margin: 0;
  padding: 0;
}
// 引了reset.css的上面部分可以不要
.block {
  display: block;
}
.select_item{
  font-size: 0;
  line-height:40px;
}

.select_item .label {
  display: inline-block;
  width: 80px;
  color: #363535;
  font-size: 12px;
  vertical-align: middle;
}

.select_item .select {
  position: relative;
  display: inline-block;
  box-sizing: border-box;
  width: 360px;
  border: 1px solid #e8e9eb;
  text-indent: 10px;
  background: #fff;
  vertical-align: middle;
}

.select_item .select .select_active {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding-right: 40px;
  color: #363535;
  font-size: 12px;
}

.select_item .select::after {
  content: "";
  position: absolute;
  display: inline-block;
  top: 50%;
  margin-top: -3px;
  right: 15px;
  width: 0;
  height: 0;
  border: 5px solid transparent;
  border-top: 7px solid #D8D8D8;
}

.select_item .select .select_menu {
  display: none;
  position: absolute;
  top: 41px;
  left: -1px;
  box-sizing: content-box;
  width: 100%;
  border: 1px solid #edf0f6;
  border-top: 0;
  z-index: 2;
  background-color: #fff;
  max-height: 201px;
  overflow-x: hidden;
  overflow-y: auto;
}

.select_item .select .select_menu li {
  height: 40px;
  line-height: 40px;
}

.select_item .select .select_menu li a {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding-right: 20px;
  color: #363535;
  font-size: 12px;
}

.select_item .select .select_menu li:hover a {
  color: #3D72ED;
  background-color: #E8E9EB;
  position: relative;
}

.select_item .select .select_menu li:hover a:after {
  content: "";
  position: absolute;
  right: 0;
  top: 0;
  width: 5px;
  height: 40px;
  background: #3d72ed;
}

js

 // 模拟下拉js
  $('.select').click(function(e){
    window.event? window.event.cancelBubble = true : e.stopPropagation();
    $(this).children('.select_menu').stop().slideToggle().css({'overflow':'auto'});
  })
  $('.select_menu li a').click(function(e){
    window.event? window.event.cancelBubble = true : e.stopPropagation();
    var text = $(this).text();
    $(this).parents('.select_menu').stop().slideUp();
    $(this).parents('.select_menu').prev('.select_active').text(text);
  })
  $(document).click(function () {
    $('.select_menu').stop().slideUp();
  })

 

你可能感兴趣的:(jquery 实现的select下拉列表)