search
HomeWeChat AppletMini Program DevelopmentHow to achieve drop-down box effect in WeChat applet? (code example)

The content of this article is to introduce how to implement the drop-down box effect in the WeChat applet? (code example). It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

There is no drop-down box in the WeChat applet component, just use it. Write it down for reference later

wxml code:


<view>
    <view> 选择接收班级</view>
    <!-- 下拉框 -->
    <view>
      <text>{{grade_name}}</text>
      <image></image>
    </view>
    <!-- 下拉需要显示的列表 -->
    <view>
      <view>
        <view>{{item}}</view>
      </view>
    </view>
  </view>

wxss Code:


/* 顶部 */.top{
  width: 100vw;
  height: 80rpx;
  padding: 0 20rpx;
  line-height: 80rpx;
  font-size: 34rpx;
  border-bottom: 1px solid #000;
}.top-text{
  float: left}/* 下拉框 */.top-selected{
    width: 50%;
    display: flex;
    float: right;
    align-items: center;
    justify-content: space-between;
    border: 1px solid #ccc;
    padding: 0 10rpx;
    font-size: 30rpx;
}/* 下拉内容 */.select_box {
    background-color: #fff;
    padding: 0 20rpx;
    width: 50%;
    float: right;
    position: relative;
    right: 0;
    z-index: 1;
    overflow: hidden;
    text-align: left;
    animation: myfirst 0.5s;
    font-size: 30rpx;
}.select_one {
    padding-left: 20rpx;
    width: 100%;
    height: 60rpx;
    position: relative;
    line-height: 60rpx;
    border-bottom: 1px solid #ccc;
}/* 下拉过度效果 */@keyframes myfirst {
    from {
        height: 0rpx;
    }
 
    to {
        height: 210rpx;
    }}/* 下拉图标 */.top-selected image{
  height:50rpx;
  width:50rpx;
  position: absolute;
  right: 0rpx;
  top: 20rpx;
}

js code:


 /**
   * 页面的初始数据   */
  data: {
    select:false,
    grade_name:'--请选择--',
    grades: [        '猛犸机器人1班',        '猛犸机器人2班',        '口才1班',
      ]
  },/**
 *  点击下拉框 */
  bindShowMsg() {    this.setData({
      select: !this.data.select
    })
  },/**
 * 已选下拉框 */
  mySelect(e) {
    console.log(e)    var name = e.currentTarget.dataset.name    this.setData({
      grade_name: name,
      select: false
    })
  },

Effect display:

How to achieve drop-down box effect in WeChat applet? (code example)

Summary: The above is the entire content of this article, I hope it will be helpful to everyone's study.

The above is the detailed content of How to achieve drop-down box effect in WeChat applet? (code example). For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:博客园. If there is any infringement, please contact admin@php.cn delete

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version