GithubHelp home page GithubHelp logo

ssshooter / img-vuer Goto Github PK

View Code? Open in Web Editor NEW
262.0 6.0 43.0 5 MB

An Mobile-First image viewer for Vue3 / 一个移动端优先的 Vue3 图片预览插件

Home Page: https://img-vuer.vercel.app/

License: MIT License

HTML 2.04% Vue 75.28% JavaScript 22.48% Shell 0.20%
image-gallery image vue-image-viewer vue vuejs

img-vuer's Introduction

img-vuer

For Vue2: https://github.com/ssshooter/img-vuer/tree/legacy

An Mobile-First image viewer for Vue3

中文 README


  • 🙆‍♀️ Easy to use
  • 👉 Swipe gesture
  • 🔍 Zoom gesture
  • Now you can use thumbnail~
  • Gallery hide when the physical back button is pressed (android device only)
  • Fix blurry after using scale()
  • 💻 compatible with PC

Now you can use both Mobile and PC Browser 😆

live demo

or scan the QRcode

Install

npm i img-vuer3 --save

Usage

// import img-vuer and install
import gallery from 'img-vuer3'
import 'img-vuer3/dist/style.css'

app.use(gallery, {
  swipeThreshold: 150, // default 100
  isIndexShow: true, // show image index, default true
  useCloseButton: true, // trigger gallery close with close button, default true
  preload: true, // preload images in the same group, default true
  sliderBackgroundColor: 'rgba(0,0,0,0.6)',
  sliderZIndex: 1001,
})
<!-- add direact to <img> -->
<img v-gallery :src="..." />

<!-- group images -->
<img v-gallery:groupName :src="..." />
<img v-gallery:groupName :src="..." />
<img v-gallery:groupName :src="..." />

<!-- OR (dynamic bind) -->
<img v-gallery="'groupName'" :src="..." />

<!-- use thumbnail, new in 0.11.0 -->
<img v-gallery :src="thumbnailSrc" data-large="originSrc" />

<!-- trigger close gallery, new in 0.14.0 -->
<button @click="$imgVuer.close()">close</button>

API

api arg description
close() / close the viwer
onIndexChange() cb $imgVuer.onIndexChange((newVal, oldVal)=>{...})
onToggle() cb on close or on open $imgVuer.onToggle((newVal, oldVal)=>{...})
changeBGColor() color change the background color of viwer $imgVuer.changeBGColor('#fff')
next() / switch to next image $imgVuer.next()
prev() / switch to previous image $imgVuer.prev()
getCurrentIndex() / /

Development

npm install

npm run dev

npm run build-lib

Troubleshooting

Abnormal page scale

Add meta

<meta
  name="viewport"
  content="width=device-width, initial-scale=1,user-scalable=0, maximum-scale=1"
/>

for a large number of large images

If you group a large number of large images, img-vuer will load all image in the same group, so it will cause unnecessary mobile data traffic and slow the page down.

You can use preload option in this situation and img-vuer will only load the image you watched.

key

Should not use index as key for the component which is added v-gallery.

License

MIT

img-vuer's People

Contributors

darksoulssssss avatar johnshere avatar pioneer-linzi avatar ssshooter avatar sun79 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

img-vuer's Issues

图片放大操作范围

放大图片的手势, 操作范围似乎是在图片范围,图片外放大手势无效。这样做如果图片是很细的一条,是否操作不便?
还有如果原本图片就是很小的一张,似乎会等比放大到全屏,这样处理好吗?如果图片很小就原大小居中展示这样处理可以不。

双指缩放问题

安卓手机,双指缩放时预览页面自动关闭。双击缩放时,图片展示不在中间,需要往下滑动才能看到图片

img-vuer lack of initialization function

part1


part2
When i enter the first page, the numbers of big picture is correct. However when i enter the second page, the numbers is wrong. It's seems to add imgs after the first time. How can i fix that?

魅族自带浏览器调不起预览图片

发现个比较尴尬的问题,一般手机浏览器可以,就是在魅族手机魅蓝note系列和华为一些低端的手机自带浏览器,无法打开预览图片,已经有了slider open这个类名,但是预览图片也没有显示出来

img src属性

Error in directive gallery bind hook: " missing src"

found in

上面的是报错信息,导致页面崩溃,请及时解决

支持ssr吗

nuxt引入报错

 Error in beforeCreate hook: "ReferenceError: document is not defined

预览图片android返回的时候有问题

如果关闭预览是遮罩层的话,history.length一直在变,然后预览几次图片之后,点击左上角想直接退出页面,需要退出好多次(预览几次就要多退几次)

How can I add a back button?

I want to be able to add a button, which would be able to trigger closeGallery event. How can I do that?
Or maybe there is some ways to trigger this event from my components.
Thank you.

图片放大后位置问题

此问题出现于 chrome 和 safari,微信、火狐等无此问题
推测与地址栏高度有关,但是移动与初始化一样是使用 window.innerHeight,为什么开始初始化可以定位到正中间?
附图
微信(正常):

火狐(正常):

safari(异常):

无法自动生成binding.arg,调用方式有疑问

< img class="item-pic" v-gallery:groupName :group1="item.id" :src="p.url" v-for="p in item.more['photos']">
跟v-for一起用的时候,group无法自定义的。下面这样,好像可以解决,貌似有点不美。 作者有什么方案吗?

inserted(el, binding) { let group = binding.value.arg // console.log(binding); el.addEventListener('click', handleClick(el, group)) 。。。 }
< img v-gallery="{arg:'groupName‘}"
class="thumbnail"
v-for="(item,index) in list1"
:src="item.src"
:key="item.src" >

手动控制关闭图片预览问题

请问可以手动关闭图片预览吗?我使用gallery.closeGallery()document.querySelector('.slider').className = 'slider close'都可以实现关闭图片预览,但是当重新点击图片的时候却不能弹出预览的图片,请问这个该怎么处理呢,谢谢大牛不吝赐教。

多图滑动问题

我这是一个商品列表,每一个商品有多个图片,可以预览,代码如下,id是商品的id按理来说是可以分不同的gallery的,现在预览的时候,可以预览到别的商品的图片,0.15.0之前是好使的,看了gallery.js做了一些String()的修改,不知道是不是有影响,麻烦看一下
<div v-for="(img,index) in data.goods.imgs" :key="'img'+data.goods.id+index" class="img-wrapper" > <img v-gallery:data.goods.id :src="common.handleImgUrl(img)" alt="商品图片"> </div>

图片分组,删除单个,图片下标错误

问题:当一个图片分组之后,有删除操作,你的unbind获取的el不是当前删除的el是最后一个el
我的分析:VUE在>=2.0之后是虚拟DOM,虚拟DOM的优点之一是操作最少的DOM节点来完成需求,减少重复渲染,当我在操作图片分组的时候我的图片组是一个数组,当我删除一个图片的时候,我只需要删除数据源即可(这就叫数据驱动了),然后虚拟DOM一比对只是移除了一个数据,然而它只是把列表的最后一个DOM节点,不管你删除的下标是几,都是remove 最后一个el, 这就是问题的所在了, 这就是为什么unbind里的El返回的总数图片组里的最后一个了。

有时间我在思考这个问题,最后这种删除的暂时不做分组了
mail: [email protected]

滑动换图太费劲

组件很不错,提个小建议,图片切换也太难了,几乎要从屏幕的一个边缘直拖到另一个边缘,返回也不明显。

另外二维码是用的哪个组件生成的?挺漂亮。

在某些情况下出现多张图无法拖动

今天出现页面中有两张图,而且是同一个组,点第一张图无法左右拖动,点第二张图就就可以拖动了,然后再点第一张图就可以拖动。

反复尝试,都是初次打开时点第一张图会无法拖动。

研究了一下源码,我看到了 VueSingle.vue 内部是通过计算宽度来决定 emit disableSwipe 或者 enableSwipe 事件的,而这两个事件就决定了 Vuer.vue 里的 allowSwipe 变量的值,这个变量的值又决定能否拖动。

可能页面内的图片宽高正好处于一个微妙的状态,导致内部计算不正确,我目前发现最方便的方法是将 Vuer.vue 里的 allowSwiper 变量改为 computed 属性,值根据 imgList 的长度是否超过 1 来决定是否能滚动。
allowSipe() { return this.imgList.length > 1; }

我不清楚这样改会不会有什么问题,但是这样改解决了我的问题。

希望作者能修复这个问题。

这里有个console没有被注释

unbind(el, binding) { console.log('unbind') // 调查keep alive后跳转是否触发unbind vm.isShow = false 。。。 }

这里有个console没有被注释,我百度了好一会儿,才发现不是我程序的事,一看你源码,发现这货了

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.