提交 6f5d6faf 编写于 作者: 郭胜强

feat: 实现组件:cover-view、cover-image

上级 34be8877
<template>
<uni-cover-image
:src="src"
v-on="$listeners">
<div
class="uni-cover-image">
<img
v-if="src"
:src="$getRealPath(src)"
@load="_load"
@error="_error">
</div>
</uni-cover-image>
</template>
<script>
export default {
name: 'CoverImage',
props: {
src: {
type: String,
default: ''
}
},
methods: {
_load ($event) {
this.$trigger('load', $event)
},
_error ($event) {
this.$trigger('error', $event)
}
}
}
</script>
<style>
uni-cover-image {
display: block;
line-height: 1.2;
overflow: hidden;
height: 100%;
width: 100%;
}
uni-cover-image img {
width: 100%;
height: 100%;
}
uni-cover-image[hidden] {
display: none;
}
uni-cover-image .uni-cover-image {
width: 100%;
height: 100%;
text-overflow: inherit;
overflow: inherit;
white-space: nowrap;
-webkit-align-items: inherit;
align-items: inherit;
-webkit-justify-content: inherit;
justify-content: inherit;
-webkit-flex-direction: inherit;
flex-direction: inherit;
font-size: 0;
display: inherit;
}
</style>
<template>
<uni-cover-view/>
<uni-cover-view
:scroll-top="scrollTop"
v-on="$listeners">
<div
ref="content"
class="uni-cover-view">
<slot/>
</div>
</uni-cover-view>
</template>
<script>
export default {
name: 'CoverView'
name: 'CoverView',
props: {
scrollTop: {
type: [String, Number],
default: 0
}
},
watch: {
scrollTop (val) {
this.setScrollTop(val)
}
},
mounted () {
this.setScrollTop(this.scrollTop)
},
methods: {
setScrollTop (val) {
var content = this.$refs.content
if (getComputedStyle(content).overflowY === 'scroll') {
content.scrollTop = this._upx2pxNum(val)
}
},
_upx2pxNum (val) {
if (/\d+[ur]px$/i.test(val)) {
val.replace(/\d+[ur]px$/i, text => {
return uni.upx2px(parseFloat(text))
})
}
return parseFloat(val) || 0
}
}
}
</script>
<style>
uni-cover-view {
display: block;
line-height: 1.2;
overflow: hidden;
white-space: nowrap;
}
uni-cover-view[hidden] {
display: none;
}
uni-cover-view .uni-cover-view {
width: 100%;
height: 100%;
text-overflow: inherit;
overflow: hidden;
white-space: inherit;
-webkit-align-items: inherit;
align-items: inherit;
-webkit-justify-content: inherit;
justify-content: inherit;
-webkit-flex-direction: inherit;
flex-direction: inherit;
-webkit-flex-wrap: inherit;
flex-wrap: inherit;
display: inherit;
overflow: inherit;
}
</style>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册