wp-UEditor 文章页面查看大图

羽化
2016-04-12 / 0 评论 / 690 阅读 / 正在检测是否收录...

前面我们已经安装好了百度的UEditor并且升级完成,本人使用一段时间后感觉图片方面还是比较薄弱的,在移动终端和PC端上都无法对图片进行放大。也没有图片相册的功能,使文章看起来很长,图片看上去很小而且不清楚,所以就感觉应该升级一下。

PhotoSwipe 是专为移动触摸设备设计的相册/画廊.兼容所有iPhone、iPad、黑莓6+,以及桌面浏览器.底层实现基于HTML/CSS/JavaScript,是一款免费开源的相册产品。

1、下载PhotoSwipe 地址:http://photoswipe.com/(本人使用的时候是4.1.1)

4445477-4a60714aae950240.png

2、解压PhotoSwipe-master可以看到很多文件,我就不一一讲解了,大家可以去看官网的API

3、拷贝dist下的所有文件到,所启用主题的lib/PhotoSwipe/没有该文件夹的就新建吧(想要封装成插件的同学就自己封装一下)

4、新建一个php写入引用PhotoSwipe的文件

<link rel="stylesheet" href="<?php bloginfo('template_directory'); ?>/lib/PhotoSwipe/photoswipe.css">
<link rel="stylesheet" href="<?php bloginfo('template_directory'); ?>/lib/PhotoSwipe/default-skin/default-skin.css">
<script src="<?php bloginfo('template_directory'); ?>/lib/PhotoSwipe/photoswipe.min.js"></script>
<script src="<?php bloginfo('template_directory'); ?>/lib/PhotoSwipe/photoswipe-ui-default.min.js"></script>

5、写入弹出放大缩小的界面,我是直接抄官网的

<!-- 图片显示详情 -->
<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. -->
        <!-- don't modify these 3 pswp__item elements, data is added later on. -->
        <div class="pswp__container">
            <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--fs" title="Toggle fullscreen"></button>

                <button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>

                <!-- Preloader demo http://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>
<!-- /图片显示详情 -->

6、写入js监听事件,img有点击事件就弹出放大缩小的模块

/**
 * Created by hua on 16-4-11.
 */

jQuery(document).ready(function() {
    $("#logPanel .entry-content img").bind("click",function(){

        var imgArr =  $(this);
        //var imgArr = $('#logPanel .entry-content img');
        var index = 0;
        var items = new Array();
        imgArr.each(function(i){

            var item = new Object();
            item.src =  imgArr[i].src;
            item.w = imgArr[i].naturalWidth;
            item.h = imgArr[i].naturalHeight;
            items.push(item);
        })

        var pswpElement = document.querySelectorAll('.pswp')[0];

        var options = {
            // history & focus options are disabled on CodePen
            index:index,
            history: false,
            focus: false,

            showAnimationDuration: 0,
            hideAnimationDuration: 0

        };

        var gallery = new PhotoSwipe( pswpElement, PhotoSwipeUI_Default, items, options);
        gallery.init();

    });
})

OK了这样图片就能放大缩小了,因为本人的文章存在异步加载,lazyload功能,所以我就想看哪张点哪张,并没有类似相册的功能。要加的话也可以,PhotoSwipe是支持异步加载图片的。

0

评论 (0)

取消