公司这沙雕 UI 整天净整些没用的,非得逼我整些科技与狠活儿 …
就这破玩意儿能表现意思来就行了,非得鼠标悬停再显示操作按钮?
直接上效果图吧 …
定义 ComplexImage 组件
代码结构
StationChnqoodeMac-mini:complex-image net.cctv3.i$ tree
.
├── assets
│ ├── icon_delete.png
│ └── icon_preview.png
└── index.vue
实现
<!-- 鼠标悬浮,带删除和预览功能的Image组件 --> <template> <div class="container"> <el-image :src="source" :alt="source" :style="styles" /> <div class="overlay"> <div class="icons"> <div class="icon" @click="onPreviewPress"> <img class="image" src="./assets/icon_preview.png" /> </div> <div style="width: 12px;" /> <div class="icon" @click="onDeletePress"> <img class="image" src="./assets/icon_delete.png" /> </div> </div> </div> </div> </template>
<script> export default { name: "complex-image", props: { source: { type: String, default: "", }, styles: { type: String, default: "", }, },
data() { return {}; }, mounted() {}, watch: {}, methods: { onPreviewPress() { console.log("onPreviewPress ..."); }, onDeletePress() { console.log("onDeletePress ..."); }, }, }; </script>
<style> .container { position: relative; display: inline-block; }
.overlay { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.5); color: white; text-align: center; line-height: 100px; /* 垂直居中 */ opacity: 0; transition: opacity 1s; align-items: center; justify-content: center; display: flex; .icons { display: flex; .icon { .image { height: 16px; width: 16px; } } } }
.container:hover .overlay { opacity: 1; } </style>
|
使用
<ComplexImage :styles="'height: 100px; width: 100px'" :source="'https://blog.cctv3.net/i.jpg'" />
|