• PhotoSwipe中文API(四)


    在幻灯片自定义HTML内容

    为了使PhotoSwipe显示HTML内容的幻灯片,你需要在幻灯片对象定义html属性。它应该包含HTML字符串或DOM元素对象。

     1 var items = [
     2     // slide 1 with HTML
     3     {
     4         html: '<div><h1>Any HTML <a href="http://example.com">content</a></h1></div>'
     5     },
     6 
     7     // slide 2 with image
     8     {
     9         src: 'path/to/image.jpg',
    10         w:600,
    11         h:200
    12     }
    13 ];
    14 
    15 
    16 // initialise as usual
    17 var gallery = new PhotoSwipe( pswpElement, PhotoSwipeUI_Default, items, options);
    18 
    19 // You don't necessarily need to have "html" property in slide object initially.
    20 // You may create it dynamically in gettingData event:
    21 /*
    22     gallery.listen('gettingData', function(index, item) {
    23         if(index === 3) {
    24             item.html = '<div>Dynamically generated HTML ' + Math.random() + '</div>';
    25         }
    26 
    27     });
    28 */
    29 
    30 // Note that init() method is called after gettingData event is bound
    31 gallery.init();

    其他重要事项:

    为了避免与第三方模块,具有html属性幻灯片冲突,不应该有SRC(图像)属性。

    PhotoSwipe是专为图像,而不是文本内容的滚轮。使用“自定义HTML”功能作为此外,例如,在相关的画廊,一个介绍的幻灯片,或图像之间的广告幻灯片。

    我们强烈不建议添加视频或使用此方法的音频内容(包括YouTube,Vimeo的等内部框架)。随着HTML5视频块触摸了它的活动在很多移动浏览器(用户将无法刷卡的话)。如果你真的需要在PhotoSwipe视频,您可以将其添加为当用户点击当前的幻灯片显示模式,可以动态地在DOM创建模态和.pswp__scroll换行元素之后添加它。

    如果启用了最初的放大/缩小的过渡,如果当前的幻灯片有HTML PhotoSwipe将自动禁用它,简单的淡入淡出的过渡将被用来代替。

    默认情况下PhotoSwipe将使只是链接(<A>)及其子元素click事件。要改变这种行为,直视isClickable元素选项或防止拖动事件的事件。

    不支持HTML滑块的放大,但。

    html:

     1 <button id="btn">Open PhotoSwipe</button>
     2 
     3 <!-- Root element of PhotoSwipe. Must have class pswp. -->
     4 <div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">
     5 
     6     <!-- Background of PhotoSwipe. 
     7          It's a separate element, as animating opacity is faster than rgba(). -->
     8     <div class="pswp__bg"></div>
     9 
    10     <!-- Slides wrapper with overflow:hidden. -->
    11     <div class="pswp__scroll-wrap">
    12 
    13         <!-- Container that holds slides. PhotoSwipe keeps only 3 slides in DOM to save memory. -->
    14         <div class="pswp__container">
    15             <!-- don't modify these 3 pswp__item elements, data is added later on -->
    16             <div class="pswp__item"></div>
    17             <div class="pswp__item"></div>
    18             <div class="pswp__item"></div>
    19         </div>
    20 
    21         <!-- Default (PhotoSwipeUI_Default) interface on top of sliding area. Can be changed. -->
    22         <div class="pswp__ui pswp__ui--hidden">
    23 
    24             <div class="pswp__top-bar">
    25 
    26                 <!--  Controls are self-explanatory. Order can be changed. -->
    27 
    28                 <div class="pswp__counter"></div>
    29 
    30                 <button class="pswp__button pswp__button--close" title="Close (Esc)"></button>
    31 
    32                 <button class="pswp__button pswp__button--share" title="Share"></button>
    33 
    34                 <button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>
    35 
    36                 <button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>
    37 
    38                 <!-- Preloader demo http://codepen.io/dimsemenov/pen/yyBWoR -->
    39                 <!-- element will get class pswp__preloader--active when preloader is running -->
    40                 <div class="pswp__preloader">
    41                     <div class="pswp__preloader__icn">
    42                       <div class="pswp__preloader__cut">
    43                         <div class="pswp__preloader__donut"></div>
    44                       </div>
    45                     </div>
    46                 </div>
    47             </div>
    48 
    49             <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
    50                 <div class="pswp__share-tooltip"></div> 
    51             </div>
    52 
    53             <button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
    54             </button>
    55 
    56             <button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
    57             </button>
    58 
    59             <div class="pswp__caption">
    60                 <div class="pswp__caption__center"></div>
    61             </div>
    62 
    63           </div>
    64 
    65         </div>
    66 
    67 </div>

    css :

     1 .hello-slide {
     2   width: 100%;
     3   max-width: 400px;
     4   color: #FFF;
     5   margin: 120px auto 0;
     6   text-align: center;
     7   
     8   font-family: "Helvetica Neue", Arial, sans-serif;
     9   
    10 }
    11 h1 {
    12   font-weight: normal;
    13 }
    14 .hello-slide a {
    15   color: #B5AEF7 !important;
    16 }

    js:

     1 var openPhotoSwipe = function() {
     2     var pswpElement = document.querySelectorAll('.pswp')[0];
     3 
     4     // build items array
     5     var items = [
     6         {
     7         html: '<div class="hello-slide"><h1>Hello world <a href="http://example.com">example.com</a></h1></div>'
     8     },
     9         {
    10             src: 'https://farm7.staticflickr.com/6175/6176698785_7dee72237e_b.jpg',
    11             w: 1024,
    12             h: 683
    13         }
    14     ];
    15     
    16     // define options (if needed)
    17     var options = {
    18              // history & focus options are disabled on CodePen        
    19         history: false,
    20         focus: false,
    21 
    22         showAnimationDuration: 0,
    23         hideAnimationDuration: 0
    24         
    25     };
    26     
    27     var gallery = new PhotoSwipe( pswpElement, PhotoSwipeUI_Default, items, options);
    28     gallery.init();
    29 };
    30 
    31 openPhotoSwipe();
    32 
    33 document.getElementById('btn').onclick = openPhotoSwipe;

    提示:您可以从CodePen下载示例在本地发挥它(编辑上CodePen - >分享 - >导出.zip文件)。

  • 相关阅读:
    助教观察记录5(10/21-11/3)
    助教观察记录4(10/07-10/20)
    助教观察记录3(9/23-10/06)
    助教观察记录1(9/5-9/15)
    2019年春季学期《C语言程序设计II》课程总结
    2020软件工程个人作业06——软件工程实践总结作业
    软件工程第二次作业
    2020软件工程作业3
    2020软件工程作业01
    神必高考数学题乱写
  • 原文地址:https://www.cnblogs.com/jiangxiaobo/p/5696001.html
Copyright © 2020-2023  润新知