微信公众号H5文中图片点击预览放大缩小、滑动效果实现(两种方式)

1、第一种直接使用微信js-sdk,jweixin-1.6.0.js

var imgs = $("#preview").find("img");
var imgsSrc =  new Array();
for(k = 0,len=imgs.length; k < len; k++) {
    imgsSrc[k] = $("#preview").find("img").eq(k).attr("src");
}
$("img.fr").click(function () { wx.previewImage({
        current: $(this).attr("src"), // 当前显示图片的http链接
        urls: imgsSrc // 需要预览的图片http链接列表[]像这种其实就是数组
    });
})

2、使用weui photo Browser和swiper

swiper.js 、jquery-weui.min.js、jquery.min.js
<style type="text/css"> /*注意图片弹出置顶防止图片过长和不居中*/ .weui-photo-browser-modal .photo-container img { max-height: 100%; } .weui-photo-browser-modal .photo-container { justify-content: center; } </style>

var pb = $.photoBrowser({
    items: imgsSrc,
    onSlideChange: function(index) {
        console.log(this, index);
    },

    onOpen: function() {
        //注意图片弹出置顶
        $(this.modal).css('z-index',6666);
        console.log("onOpen", this);
    },
    onClose: function() {
        console.log("onClose", this);
    }
});
$("img.fr").click(function () {
    pb.open(imgsSrc.indexOf($(this).attr("src")));
})

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值