zoukankan      html  css  js  c++  java
  • vue+原生JavaScript实现slideDown与slideUp[简单思路]

    整个代码如下:

    <template>
      <div style="400px;margin:100px auto;">
                <div class="con">
                        <div class="same_module">
                                <div class="title up" @click="slide($event)"><span>标题一</span><i class="arrow"></i></div>
                                <div class="detail" style="height:0">
                                        <div class="inner">
                                                <p>这是一段文本</p>
                                                <p>这是一段文本</p>
                                                <p>这是一段文本</p>
                                                <p>这是一段文本</p>
                                        </div>
                                </div>
                        </div>
                </div>
      </div>
    </template>
    
    <script>
    export default {
      data () {
        return {
            
        }
      },
        methods:{
            slide:function(event){
                let curTarget = event.currentTarget,
                        containsCurClass = curTarget.classList.contains("up"),
                        nextSibling = curTarget.nextSibling;
                while(nextSibling.nodeType == 3 && /s/.test(nextSibling.nodeValue)){
                    nextSibling = nextSibling.nextSibling;
                };
                let detailScrollHeight = nextSibling.scrollHeight;
                if(containsCurClass){
                        curTarget.classList.remove("up");
                        this.toggleSlide(nextSibling,detailScrollHeight,'500');
                }else{
                    curTarget.classList.add("up");
                    this.toggleSlide(nextSibling,0,'500');
                }
            },
            toggleSlide:function(dom,height,time){
                dom.style.transition = 'height ' + time + 'ms';
                dom.style.height = height + 'px';
            }
        }
    }
    </script>
    <style scoped>
        .same_module{border:1px solid grey;}
        .title{color:#fff;height:30px;line-height:30px;background:blue;padding:0 10px;cursor: pointer;overflow: hidden;}
        .title span{vertical-align:middle;}
        .title .arrow{float: right;}
        .detail{overflow: hidden;}
        .detail .inner{padding:5px 10px;background: #808080;color:#fff;}
        .detail p{line-height: 26px;}
        .arrow{
            display: inline-block;
        border-top: 2px solid;
        border-right: 2px solid;
        width: 8px;
        height: 8px;
        border-color: #EA6000;
        transform: rotate(315deg);
            position: relative;
            transition: all 0.5s ease-in;
            transform-origin: center center;
            top:50%;
            margin-top:-10px;
        }
        .up .arrow{
                transform: rotate(135deg);
        }
        
    </style>

    参考地址:vue也可以 slidedown

  • 相关阅读:
    安装adobe,路径My Pictures或卷无效。请重新输入。
    PrintDocument打印、预览、打印机设置和打印属性的方法(较完整) .
    C# 生成CODE128条码
    SQL2005 安装时 “性能监视器计数器要求(错误)” 解决方案
    Siebel escript学习笔记
    siebel 界面搭建
    Siebel Tools 开发笔记
    Siebel Tools配置
    Oracle:environment variable "PATH" does not exceed the recommended length
    IOS开发入门实例
  • 原文地址:https://www.cnblogs.com/moqiutao/p/10552736.html
Copyright © 2011-2022 走看看