vue.js - 基于类绑定的 Vue JS 转换切换 - 轻松上下
问题描述
使用 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;
}
解决方案
我做了一个示例。检查一次。这可能会有所帮助。(您在 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>
推荐阅读
- sql - SQL中的相对比例
- angular - Angular io:在占位符中添加多行
- java - 将自定义更改提交到没有 pojo 的 javers 存储库
- java - 如何在 Java 中创建 .sfm 文件?
- python - 如何在 Pyinstaller 中包含 chromedriver 可执行文件,以便它适用于没有 chromedriver 的计算机?
- c# - 如何从 Azure 表存储中的分区键列表中查询
- spring-boot - Spring Boot 1.5.x Gradle Plugin 可执行jar
- python - 方法放在哪里?类/模块职责
- java - javap在jar中找到类,但java没有
- arrays - 有什么方法可以通知编译器数组已排序,以便可以更快地完成搜索?