移动端下拉选择框

<!doctype html>

<html>

<head>

<meta charset="UTF-8">

<title>移动端下拉框选择</title>

<style type="text/css">

    * {

        margin: 0px;

        padding: 0px;

        -webkit-tap-highlight-color: rgba(0, 0, 0, 0);

        -webkit-touch-callout: none;

        -webkit-user-select: none;

        -webkit-appearance: none;

        outline: none;

        word-break: break-all;

        box-sizing: border-box;

        -webkit-box-sizing: border-box;

    }

    html, body {

        width: 100%;

        font-family: "PingFang SC-Medium,sans-serif", "Noto Sans CJK SC,sans-serif", Arial, "Microsoft YaHei";

        font-size: 100px;

        background-color: #f5f5f5;

    }

    body {

       font-size: 62.5%;

       height: 100%;

       line-height: 1;

   }

   ul, ol, li {

    list-style: none;

}

.testselect {

    position: relative;

    padding: 0.09rem 0.32rem;

    display: -webkit-box;

    display: box;

    display: -moz-box;

    overflow: hidden;

    margin-top: 0.5rem;

    border: 1px solid #d4d4d4;

}

.testselect label {

    display: block;

    width: 1.72rem;

    height: 0.62rem;

    line-height: 0.62rem;

    font-size: 0.3rem;

    color: #3e3e3e;

}

.testselect input {

    -webkit-box-flex: 1;

    -moz-box-flex: 1;

    -ms-flex: 1;

    flex: 1;

    width: 100%;

    line-height: 0.62rem;

    font-size: 0.3rem;

    margin-left: -0.3rem;

}

.infor-unit {

    position: absolute;

    right: 0;

    top: 0.4rem;

    width: 0.46rem;

    text-align: right;

}

.arrow-right {

    display: inline-block;

    position: absolute;

    top: 50%;

    right: 5.3rem;

    content: ">";

    vertical-align: middle;

    width: 0.13rem;

    height: 0.22rem;

    background-position: -2.38rem -0.42rem;

    background-size: 3.65rem 1.06rem;

    margin-top: -0.11rem;

    color: #999;

    font-size: 0.49rem;

}

.chicon-clear{

    font-size: 0.49rem;

    color: #999;

    font-style: normal;

    margin-left: -.7rem;

}

.mask-layer {

    position: fixed;

    width: 100%;

    height: 100%;

    left: 0;

    top: 0;

    z-index: 2010;

    background-color: rgba(0, 0, 0, 0.6);

}

.payment {

    position: relative;

    width: 100%;

    height: 100%;

}

.payment-content {

    position: absolute;

    bottom: 0;

    left: 0;

    width: 100%;

    background-color: #fff;

}

.payment-title {

    display: -webkit-box;

    display: box;

    display: -moz-box;

    height: 0.9rem;

    background-color: #f5f5f5;

}

.payment-title > a {

    display: inline-block;

    line-height: 0.9rem;

    padding: 0 0.3rem;

    font-size: 0.34rem;

    color: #0066cc;

    text-decoration: none;

}

.payment-title > h3 {

    -webkit-box-flex: 1;

    -moz-box-flex: 1;

    -ms-flex: 1;

    flex: 1;

    width: 100%;

    font-weight: bold;

    text-align: center;

    line-height: 0.9rem;

    font-size: 0.36rem;

    color: #111111;

}

.payment-list {

    padding: 0.2rem 0 0.4rem;

    height: 3.5rem;

    /*居中改高*/

    /*height: 7rem;*/

    overflow: hidden;

}

.payment-list li {

    text-align: center;

    line-height: 0.9rem;

    font-size: 0.32rem;

    color: #666666;

}

.swiper-slide-active {

    font-weight: bold;

    font-size: 0.4rem;

    color: #111111;

    border-top: 1px solid #ccc;

    border-bottom: 1px solid #ccc;

}

.payment-content-center{

   width: 82%;

   height: 62%;

   background: #f3f3f3;

   position: fixed;

   top: 19%;

   z-index: 22;

   left: 50%;

   margin-left: -41%;

   font-size: .32rem;

   color: #000;

   text-align: center;

   overflow-y: auto;

}

</style>

</head>

<body>

<div class="testselect"  id="app">

  <label>门店</label>

  <input v-model="selectVal" type="text" readonly="readonly" placeholder="请选择" v-on:click="selectDept"/>

  <div class="clear" v-on:click="clearDepartment()" v-if="selectVal"><i class="chicon-clear">x</i></div>

  <div class="infor-unit" v-else v-on:click="selectDept()"><i class="arrow-right">></i></div>

</div>

<article class="mask-layer" id="footer-select" style="display: none;">

  <div class="payment"></div>

  <div class="payment-content">

      <!-- 默认是底部显示,可以把payment-content改成payment-content-center居中显示 -->

      <div class="payment-title">

        <a href="javascript:void(0);" class="close-btn fn-btn">取消</a>

        <h3>门店</h3>

        <a href="javascript:void(0);" class="confirm-btn fn-btn">确定</a>

    </div>

    <div class="payment-list swiper-container">

        <ul class="swiper-wrapper" id="footer-tab-wapper"></ul>

   </div>

</div>

</article>

<script type="text/javascript" src="https://cdn.bootcss.com/zepto/1.1.5/zepto.min.js"></script>

<script type="text/javascript" src="https://cdn.bootcss.com/vue/2.5.12/vue.min.js"></script>

<script type="text/javascript" src="https://cdn.bootcss.com/Swiper/4.0.5/js/swiper.js"></script>

<script type="text/javascript">

var app = new Vue({

data: {

    selectVal:'',//下拉选择的值

    isRenderSel:false//是否渲染好了下拉框值

},

created: function() {

   this.storeJson = [

   "深圳1店",

   "深圳2店",

   "深圳3店",

   "深圳4店",

   "深圳5店",

   "深圳6店",

   "深圳7店",

   "深圳8店",

   "深圳9店",

   "深圳10店",

   "深圳11店",

   "深圳12店",

   "深圳13店",

   "深圳14店",

   "深圳15店",

   "深圳16店",

   "深圳17店",

   "深圳18店",

   "深圳19店",

   "深圳20店",

   "深圳21店",

   "深圳22店",

   "深圳23店",

   "深圳24店",

   "深圳25店"

   ]

},

mounted: function() {

   console.log(this.storeJson.length);

},

methods: {

   selectDept: function () {

      var self = this;

      self.showFooterTab(self.storeJson);

  },

  clearDepartment: function () {

      var self = this;

      self.selectVal = '';

  },

  showFooterTab: function(arr){

     var me = this;

     if(this.isRenderSel){

         this.footerSwiper.slideTo(0);

         this.footerTabEl.show();

     }else{

         var el = this.footerTabEl= $('#footer-select');

         this.wrapperEl = $('#footer-tab-wapper');

         if(arr && arr.length > 0){

            this.wrapperEl.html("");

            for(var i=0,j=arr.length; i<j; i++){

                this.wrapperEl.append('<li class="swiper-slide">'+arr[i]+'</li>');

            }

            el.show();

        }

        this.footerSwiper = new Swiper('.swiper-container', {

         direction: 'vertical',

                    slidesPerView: 3,//底部参数用3,

                    spaceBetween: 0,

                    centeredSlides: true,

                    slideActiveClass : 'swiper-slide-active',

                });



        el.find('.close-btn').click(function(){

         el.hide();

     });



        $('.payment').click(function(){

         el.hide();//单击选择框其它部分也关闭

     });



        this.isRenderSel = true;



    }



   this.footerTabEl.find('.confirm-btn').off('click').click(function(){

       var txt = me.wrapperEl.find('.swiper-slide-active').text();

       me.selectVal = txt;

       me.footerTabEl.hide();

   })

}

},

watch: {}

}).$mount("#app")

</script>

</body>

</html>

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 160,646评论 4 366
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,979评论 1 301
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 110,391评论 0 250
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 44,356评论 0 215
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,740评论 3 293
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,836评论 1 224
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 32,022评论 2 315
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,764评论 0 204
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,487评论 1 246
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,728评论 2 252
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,200评论 1 263
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,548评论 3 260
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,217评论 3 241
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,134评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,921评论 0 201
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,919评论 2 283
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,766评论 2 274

推荐阅读更多精彩内容