如何在uni-app里将一个图片做成按钮并给它附加一个每次点击都旋转180度的动画,并在每次点击时生成或收起一个列数为2,行数为4的列表,在生成表格的时候,使列表处于界面最上端,并
时间: 2024-05-30 19:13:08 浏览: 50
animate.css-uni-app动画样式文件
且能够在点击表格外的区域时收起表格?谢谢!
感谢您的提问。针对您的问题,我提供如下解答:
在uni-app中,您可以使用weui框架中的weui-actionSheet组件来生成一个类似于您所描述的表格,该组件可以在父容器的顶部生成一个类似于下拉菜单的列表。可以在点击图片按钮时,通过设置weui-actionSheet的show属性为true,来打开列表,同时给图片按钮应用一个CSS3的动画来实现旋转的效果。示例代码如下:
<template>
<view>
<image src="/static/image.png" @tap="showList" class="btn"/>
<weui-actionsheet :show="show">
<weui-actionsheet-cell>1</weui-actionsheet-cell>
<weui-actionsheet-cell>2</weui-actionsheet-cell>
<weui-actionsheet-cell>3</weui-actionsheet-cell>
<weui-actionsheet-cell>4</weui-actionsheet-cell>
<weui-actionsheet-cell>5</weui-actionsheet-cell>
</weui-actionsheet>
</view>
</template>
<script>
import weuiActionsheet from "@/components/weui-actionsheet/weui-actionsheet.vue";
export default {
data() {
return {
show: false
};
},
components: {
"weui-actionsheet": weuiActionsheet
},
methods: {
showList() {
this.show = !this.show;
const btn = document.querySelector(".btn");
btn.classList.toggle("rotate");
}
}
};
</script>
<style>
.btn {
width: 100px;
height: 100px;
}
.rotate {
-webkit-animation: 1s rotate-ani;
animation: 1s rotate-ani;
}
@keyframes rotate-ani {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(180deg);
}
}
</style>
至于如何在点击表格外的区域时收起表格,可以通过监听weui-actionsheet组件的取消事件,来实现点击表格以外的区域时自动隐藏表格。示例代码如下:
<template>
<view>
<image src="/static/image.png" @tap="showList" class="btn"/>
<weui-actionsheet :show="show" @cancel="hideList">
<weui-actionsheet-cell>1</weui-actionsheet-cell>
<weui-actionsheet-cell>2</weui-actionsheet-cell>
<weui-actionsheet-cell>3</weui-actionsheet-cell>
<weui-actionsheet-cell>4</weui-actionsheet-cell>
<weui-actionsheet-cell>5</weui-actionsheet-cell>
</weui-actionsheet>
</view>
</template>
<script>
import weuiActionsheet from "@/components/weui-actionsheet/weui-actionsheet.vue";
export default {
data() {
return {
show: false
};
},
components: {
"weui-actionsheet": weuiActionsheet
},
methods: {
showList() {
this.show = !this.show;
const btn = document.querySelector(".btn");
btn.classList.toggle("rotate");
},
hideList() {
this.show = false;
const btn = document.querySelector(".btn");
btn.classList.remove("rotate");
}
}
};
</script>
<style>
.btn {
width: 100px;
height: 100px;
}
.rotate {
-webkit-animation: 1s rotate-ani;
animation: 1s rotate-ani;
}
@keyframes rotate-ani {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(180deg);
}
}
</style>
阅读全文