【问题标题】:Vue JS transition toggle based of class binded - ease down and up基于类绑定的 Vue JS 转换切换 - 轻松上下
【发布时间】:2019-06-11 07:25:13
【问题描述】:

使用 Vue JS,我试图通过轻松转换 max-height 属性来降低/关闭来转换阅读更多/阅读更少。

此 itemBio 位于引导 vue 模式中(如果相关)。

如果 readMore 数据为真,则 readMore 类绑定到 itemBio 类 div。然后将 max-height 属性激活为 100%。

虽然似乎根本不起作用。立即显示/关闭 div。

这是我目前所拥有的:

.itemBio {
   max-height: 51px;
   overflow: hidden;
   transition: max-height 5s ease;

   &.readMore {
     max-height: 100%;
     overflow: auto;
     transition: max-height 5s ease;

     &::-webkit-scrollbar {
       display: none;
     }
   }
 }

   <div class="itemBio font-14 text-grey69 w-100"
                             :class="{'readMore':readMore}"
                             style="line-height: 17px;"
                             :ref="'countLines' + menuItem.uuid">

                            {{ menuItem.description }}

                            <button @click="$refs.allergensModal.show()"
                                    class="mt-10 w-100 text-left"
                                    v-if="dietaryTrue !== 0"
                            >
                                <span class="allergen green"
                                      v-if="menuItem.dietary.vegetarian">
                                    V
                                </span>

                                <span class="allergen aqua"
                                      v-if="menuItem.dietary.vegan">
                                    VG
                                </span>

                                <span class="allergen gold"
                                      v-if="menuItem.dietary.gluten_free">
                                    GF
                                </span>

                                <span class="allergen pink"
                                      v-if="menuItem.dietary.halal">
                                    HA
                                </span>

                                <span class="allergen yellow"
                                      v-if="menuItem.dietary.soy_free">
                                    SF
                                </span>

                                <span class="allergen brown"
                                      v-if="menuItem.dietary.nut_free">
                                    NF
                                </span>

                                <span class="allergen blue"
                                      v-if="menuItem.dietary.dairy_free">
                                    DF
                                </span>
                            </button>
                        </div>

   <button class="text-teal font-black font-12" @click="showItemBio()" v-if="lines > 2">
      <span v-if="!readMore">Read More</spa`enter code here`n>
      <span v-if="readMore">Read Less</span>
   </button>


   Typescript:

      readMore: boolean = false;

      showItemBio() {
         this.readMore = !this.readMore;
      }

【问题讨论】:

    标签: vue.js transition


    【解决方案1】:

    我做了一个示例。检查一次。这可能会有所帮助。(您在 max-height 中提到 100%,在开始 max-height 时您提到 51px 这可能是不转换的问题。同时保持 px 或 %)

    <template>
    <div id="app">
        <div class="paragraph" :class="{showmore:checkStatus}">
           <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.             Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
        It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
        Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
        It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
    
      </p>
    </div>
    <button @click="changeData">{{ readStatus }}</button>
      </div>
      </template>
    
    <script>
      export default {
      name: 'App',
      data:function(){
    return {
      readStatus:'readmore',
      checkStatus:false
    }
    },
    methods:{
    changeData:function(){
    
      if(this.readStatus=='readmore'){
        this.readStatus='readless';
        this.checkStatus=true;
      }else{
        this.readStatus='readmore';
        this.checkStatus=false;
      }
      }
      }
     }
      </script>
    
    <style scoped>
      .paragraph {
    max-height: 100px;
    overflow: hidden;
    transition: max-height 2s;
    
     }
     .paragraph p{
      color: black;
     }
     .showmore{
    max-height: 500px;
    overflow: auto;
     }
    </style>
    

    【讨论】:

      猜你喜欢
      • 2019-06-08
      • 1970-01-01
      • 1970-01-01
      • 2018-04-13
      • 2016-10-31
      • 2017-11-20
      • 1970-01-01
      • 1970-01-01
      • 2016-08-08
      相关资源
      最近更新 更多