-3

Airbnb 使用什么库(或不使用)进行滑块切换?附上截图。我很想知道。我查看了他们的来源,但无法识别图书馆。滑块的屏幕截图

4

1 回答 1

2

我不知道他们在使用什么,但使用 transition 和 jquery 重新创建并不难。

#stage .slider-frame {
  position: relative;
  display: block;
  margin: 0;
  padding: 0;
  margin: 0 auto;
  width: 70px;
  height: 23px;
  background-color:#62C100;
  border-radius:50px;
  -moz-box-shadow: inset 0 0 5px 0px #888;
  -webkit-box-shadow: inset 0 0 5px 0px#888;
  box-shadow: inset 0 0 5px 0px #888;
}
#stage .slider-frame .slider-button {
  display: block;
  margin: 0;
  padding: 0;
  width: 23px;
  height: 21px;
  line-height: 27px;
  background: #FEFEFe;
  -moz-border-radius: 50px;
  border-radius: 50px;
  border: 1px solid #CCC;
  -webkit-transition: all 0.25s ease-in-out;
  -moz-transition: all 0.25s ease-in-out;
  transition: all 0.25s ease-in-out;
  color: #fff;
  font-family:Helvetica;
  font-size:11px;
  font-weight: bold;
  cursor: pointer;
}
#stage .slider-frame .slider-button.on {
  margin-left: 45px;
}

然后是这样的:

$('.slider-button').toggle(function(){
    $(this)
        .addClass('on')
        .parent()
        .next('input[type="checkbox"]')
        .attr('checked', 'checked');
},function(){
    $(this)
        .removeClass('on')
        .parent()
        .next('input[type="checkbox"]')
        .removeAttr('checked');
});

这是一个JSFiddle

于 2013-04-27T19:08:43.223 回答