vant components
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
## 0.0.2 (2017-01-20)
|
||||
|
||||
* 改了bug A
|
||||
* 加了功能B
|
||||
|
||||
## 0.0.1 (2017-01-10)
|
||||
|
||||
* 第一版
|
||||
@@ -0,0 +1,26 @@
|
||||
# @youzan/<%= name %>
|
||||
|
||||
!!! 请在此处填写你的文档最简单描述 !!!
|
||||
|
||||
[![version][version-image]][download-url]
|
||||
[![download][download-image]][download-url]
|
||||
|
||||
[version-image]: http://npm.qima-inc.com/badge/v/@youzan/<%= name %>.svg?style=flat-square
|
||||
[download-image]: http://npm.qima-inc.com/badge/d/@youzan/<%= name %>.svg?style=flat-square
|
||||
[download-url]: http://npm.qima-inc.com/package/@youzan/<%= name %>
|
||||
|
||||
## Demo
|
||||
|
||||
## Usage
|
||||
|
||||
## API
|
||||
|
||||
| 参数 | 说明 | 类型 | 默认值 | 可选值 |
|
||||
|-----------|-----------|-----------|-------------|-------------|
|
||||
| className | 自定义额外类名 | string | '' | '' |
|
||||
|
||||
|
||||
|
||||
|
||||
## License
|
||||
[MIT](https://opensource.org/licenses/MIT)
|
||||
@@ -0,0 +1,3 @@
|
||||
import ImagePreview from './src/image-preview.js';
|
||||
|
||||
export default ImagePreview;
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"name": "@youzan/van-image-pewview",
|
||||
"version": "0.0.1",
|
||||
"description": "image preview component",
|
||||
"main": "./index.js",
|
||||
"author": "zhangmin <zhangmin@youzan.com>",
|
||||
"license": "MIT",
|
||||
"devDependencies": {},
|
||||
"dependencies": {}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
import Vue from 'vue';
|
||||
import ImagePreview from './image-preview.vue';
|
||||
|
||||
let instance;
|
||||
|
||||
const ImagePreviewConstructor = Vue.extend(ImagePreview);
|
||||
|
||||
const initInstance = () => {
|
||||
instance = new ImagePreviewConstructor({
|
||||
el: document.createElement('div')
|
||||
});
|
||||
};
|
||||
|
||||
var ImagePreviewBox = images => {
|
||||
if (!instance) {
|
||||
initInstance();
|
||||
}
|
||||
|
||||
if (!instance.value) {
|
||||
instance.images = images;
|
||||
|
||||
document.body.appendChild(instance.$el);
|
||||
|
||||
Vue.nextTick(() => {
|
||||
instance.value = true;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export default ImagePreviewBox;
|
||||
@@ -0,0 +1,91 @@
|
||||
<template>
|
||||
<transition name="image-fade">
|
||||
<div class="van-image-preview" ref="previewContainer" v-show="value" @click="handlePreviewClick">
|
||||
<van-swipe>
|
||||
<van-swipe-item v-for="item in images">
|
||||
<img class="van-image-preview__image" @load="handleLoad" :src="item" alt="">
|
||||
</van-swipe-item>
|
||||
</van-swipe>
|
||||
</div>
|
||||
</transition>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import Popup from 'src/mixins/popup';
|
||||
import ZanSwipe from 'packages/swipe';
|
||||
import ZanSwipeItem from 'packages/swipe-item';
|
||||
|
||||
export default {
|
||||
name: 'van-image-preview',
|
||||
|
||||
mixins: [Popup],
|
||||
|
||||
components: {
|
||||
ZanSwipe,
|
||||
ZanSwipeItem
|
||||
},
|
||||
|
||||
props: {
|
||||
overlay: {
|
||||
default: true
|
||||
},
|
||||
|
||||
lockOnScroll: {
|
||||
default: true
|
||||
},
|
||||
|
||||
closeOnClickOverlay: {
|
||||
default: true
|
||||
}
|
||||
},
|
||||
|
||||
data() {
|
||||
return {
|
||||
images: [],
|
||||
viewportSize: null
|
||||
};
|
||||
},
|
||||
|
||||
methods: {
|
||||
handlePreviewClick() {
|
||||
this.value = false;
|
||||
},
|
||||
|
||||
handleLoad(event) {
|
||||
const containerSize = this.$refs.previewContainer.getBoundingClientRect();
|
||||
const ratio = containerSize.width / containerSize.height;
|
||||
const target = event.currentTarget;
|
||||
const targetRatio = target.width / target.height;
|
||||
|
||||
const centerClass = 'van-image-preview__image--center';
|
||||
const bigClass = 'van-image-preview__image--big';
|
||||
|
||||
if (targetRatio > ratio) {
|
||||
target.className += (' ' + centerClass);
|
||||
} else {
|
||||
target.className += (' ' + bigClass);
|
||||
}
|
||||
},
|
||||
|
||||
close() {
|
||||
if (this.closing) return;
|
||||
|
||||
this.closing = true;
|
||||
|
||||
this.value = false;
|
||||
|
||||
if (this.lockOnScroll) {
|
||||
setTimeout(() => {
|
||||
if (this.modal && this.bodyOverflow !== 'hidden') {
|
||||
document.body.style.overflow = this.bodyOverflow;
|
||||
}
|
||||
this.bodyOverflow = null;
|
||||
}, 200);
|
||||
}
|
||||
|
||||
this.opened = false;
|
||||
this.doAfterClose();
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
Reference in New Issue
Block a user