Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <template>
- <div>
- <button id="btn" v-on:click="onOpenGallery(index)" v-for="(item,index) in items" :key="index">{{item.name}}</button>
- <!-- Root element of PhotoSwipe. Must have class pswp. -->
- <div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">
- <!-- Background of PhotoSwipe.
- It's a separate element, as animating opacity is faster than rgba(). -->
- <div class="pswp__bg"></div>
- <!-- Slides wrapper with overflow:hidden. -->
- <div class="pswp__scroll-wrap">
- <!-- Container that holds slides. PhotoSwipe keeps only 3 slides in DOM to save memory. -->
- <div class="pswp__container">
- <!-- don't modify these 3 pswp__item elements, data is added later on -->
- <div class="pswp__item"></div>
- <div class="pswp__item"></div>
- <div class="pswp__item"></div>
- </div>
- <!-- Default (PhotoSwipeUI_Default) interface on top of sliding area. Can be changed. -->
- <div class="pswp__ui pswp__ui--hidden">
- <div class="pswp__top-bar">
- <!-- Controls are self-explanatory. Order can be changed. -->
- <div class="pswp__counter"></div>
- <button class="pswp__button pswp__button--close" title="Close (Esc)"></button>
- <button class="pswp__button pswp__button--share" title="Share"></button>
- <button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>
- <button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>
- <!-- Preloader demo https://codepen.io/dimsemenov/pen/yyBWoR -->
- <!-- element will get class pswp__preloader--active when preloader is running -->
- <div class="pswp__preloader">
- <div class="pswp__preloader__icn">
- <div class="pswp__preloader__cut">
- <div class="pswp__preloader__donut"></div>
- </div>
- </div>
- </div>
- </div>
- <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
- <div class="pswp__share-tooltip"></div>
- </div>
- <button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
- </button>
- <button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
- </button>
- <div class="pswp__caption">
- <div class="pswp__caption__center"></div>
- </div>
- </div>
- </div>
- </div>
- </div>
- </template>
- <script>
- import PhotoSwipe from 'photoswipe/dist/photoswipe'
- import PhotoSwipeUI_Default from 'photoswipe/dist/photoswipe-ui-default'
- import 'photoswipe/dist/photoswipe.css'
- import 'photoswipe/dist/default-skin/default-skin.css'
- export default {
- components: {
- // eslint-disable-next-line vue/no-unused-components
- PhotoSwipe,PhotoSwipeUI_Default
- },
- data:() => ({
- pswpElement:null,
- options: {
- // history & focus options are disabled on CodePen
- history: false,
- focus: false,
- showAnimationDuration: 0,
- hideAnimationDuration: 0,
- index:0,
- shareButtons: [
- {id:'download', label:'Скачать', url:'{{raw_image_url}}', download:true}
- ],
- },
- items:[
- {
- name:"gffg",
- images: [{
- src: 'https://farm2.staticflickr.com/1043/5186867718_06b2e9e551_b.jpg',
- w: 1024,
- h: 683,
- },
- {
- src: 'https://farm7.staticflickr.com/6175/6176698785_7dee72237e_b.jpg',
- w: 1024,
- h: 683,
- }
- {
- html: '<div class="video-wrapper"><video playsinline controls controlsList="nodownload"><source src="http://j/fj45"/></video></div>',
- title:'1',
- },
- ]
- },
- {
- name:"22222222222",
- images: [{
- src: 'https://live.staticflickr.com/4838/45925416992_9af1b42067_k.jpg',
- w: 1024,
- h: 683,
- },
- {
- src: 'https://live.staticflickr.com/5598/14934282524_577a904d2b_k.jpg',
- w: 1024,
- h: 683,
- },
- {
- src: 'https://live.staticflickr.com/5213/5508784414_d2d84f9c92_b.jpg',
- w: 1024,
- h: 683,
- },
- ]
- },
- ]
- }),
- methods: {
- pause:function(){
- window.document.querySelectorAll('video')
- .forEach(function(Item) {
- Item.pause();
- // Item.currentTime = 0
- }
- );
- },
- onOpenGallery( index){
- var self=this;
- // this.options.index=i;
- var gallery = new PhotoSwipe( this.pswpElement, PhotoSwipeUI_Default, this.items[index].images, this.options);
- gallery.listen('gettingData', function(index, item) {
- if (item.w < 1 || item.h < 1) { // unknown size
- var img = new Image();
- img.onload = function() { // will get size after load
- item.w = this.width; // set image width
- item.h = this.height; // set image height
- gallery.invalidateCurrItems(); // reinit Items
- gallery.updateSize(true); // reinit Items
- }
- img.src = item.src; // let's download image
- }
- });
- gallery.listen('afterChange', function() {
- // window.console.log(window.document.querySelectorAll('.my_video'),gallery.currItem);
- // eslint-disable-next-line no-undef
- });
- gallery.listen('close', function() {
- self.pause();
- });
- gallery.listen('beforeChange', function() {
- // self.removeVideo();
- self.pause();
- });
- gallery.init();
- }
- },
- mounted() {
- this.pswpElement = document.querySelectorAll('.pswp')[0];
- }
- }
- </script>
- <style >
- .video-wrapper video{
- margin: 0;
- position: absolute;
- top: 50%;
- left: 50%;
- margin-right: -50%;
- transform: translate(-50%, -50%);
- padding-top: 40px;
- max-width:100%;
- max-height:100%;
- }
- </style>
Add Comment
Please, Sign In to add comment