-
![]()
+
+
@@ -30,25 +33,46 @@ export default {
data() {
return {
- image: 'https://img.yzcdn.cn/upload_files/2017/03/02/FhDtQ7okM18PeQ3P0RAfIzVADUEq.jpg'
+ image: '',
+ viewportSize: null
};
},
- mounted() {
- this.open();
- this.previewSize = this.$refs.previewContainer.getBoundingClientRect();
- },
-
- computed: {
+ methods: {
+ handlePreviewClick() {
+ this.value = false;
+ },
/**
* 图片样式计算
* 根据屏幕自适应显示最长边
*/
- imageStyle() {
- }
- },
+ computeImageStyle() {
+ let previewSize = this.$refs.previewContainer.getBoundingClientRect();
+ let img = new Image();
+ let _this = this;
+
+ img.onload = function() {
+ let imgRatio = parseFloat(this.width / this.height);
+ let previewRatio = parseFloat(previewSize.width / previewSize.height);
+
+ if (previewRatio <= imgRatio) {
+ let top = (previewSize.height - parseInt(previewSize.width / imgRatio, 10)) / 2;
+ _this.imageStyle = {
+ width: '100%',
+ height: 'auto',
+ top: top + 'px'
+ };
+ } else if (previewRatio > imgRatio) {
+ _this.imageStyle = {
+ width: 'auto',
+ height: '100%'
+ };
+ }
+ };
+
+ img.src = this.image;
+ },
- methods: {
close() {
if (this.closing) return;
diff --git a/packages/zanui-css/src/image_preview.css b/packages/zanui-css/src/image_preview.css
index 2ae2a76ce..ad5ded9aa 100644
--- a/packages/zanui-css/src/image_preview.css
+++ b/packages/zanui-css/src/image_preview.css
@@ -1,15 +1,29 @@
@component-namespace zan {
@b image-preview {
- position: absolute;
+ position: fixed;
+ top: 0;
+ left: 0;
width: 100%;
- height: 75%;
- overflow: hidden;
+ height: 100%;
+ overflow: scroll;
@e image {
display: block;
width: 100%;
height: auto;
- margin: 0 auto;
+ transition: .2s;
+ position: absolute;
+ left: 0;
+
+ @m center {
+ top: 50%;
+ transform: translate3d(0, -50%, 0);
+ }
+
+ @m top {
+ top: 0;
+ transform: none;
+ }
}
}
}
diff --git a/src/index.js b/src/index.js
index 4b530417a..46c242915 100644
--- a/src/index.js
+++ b/src/index.js
@@ -47,7 +47,6 @@ const install = function(Vue) {
Vue.component(Badge.name, Badge);
Vue.component(Search.name, Search);
Vue.component(Step.name, Step);
- Vue.component(ImagePreview.name, ImagePreview);
};
// auto install