仿朋友圈图片查看功能
2017-08-23 19:00
211 查看
准备
swiper下载swiper轮播图插件,官网:http://www.swiper.com.cn/download/index.html
只需要swiper.min.js 和 swiper.min.css 即可版本不限。
jquery.js
css
#imglist img{ width: 20%; height: 70px; float: left } .swiper-container{ position: fixed; top: 0px; left: 0px; right: 0; bottom: 0; background: rgba(0, 0, 0, 0.7); z-index: 99; width: 100%; height: 100%; display: none }
html
<!-- 引入上述准备的相关文件--> <!-- 缩略图 --> <div id="imglist"> <!-- 此处是动态数据 --> </div> <!--此处轮播图--> <div> <div class="swiper-wrapper" style=""> <!-- 此处是动态数据 --> </div> <div class="swiper-pagination"></div> </div>
js
//img为图片数组 var img=['1.jpg','2.jpg','3.jpg'] for(var i=0; i<img.length;i++){ var str=' <img class="pimg" src='+img[i]+' onclick="change('+i+')"/>' $("imglist").append(str); //缩略图 var str1='<div class="swiper-slide"><img src='+img[i]+' a7fc alt=""></div>'; $(".swiper-wrapper").append(str1) //图片展示 name(i); } //对图片进行缩放调整 function name(i){ $(".swiper-container .swiper-slide").eq(i).find('img').attr("src", img[i]).load(function(){ var windowW = $(window).width(); var windowH = $(window).height(); var realWidth = this.width; var realHeight = this.height; var scale = 1; var scaleW = 1; var scaleH = 1; var x=0; var y=0; if(realWidth>windowW ||realHeight>windowH){ scaleW = windowW/realWidth; scaleH = windowH/realHeight; //计算一个缩放比例 scale = Math.min(scaleW,scaleH); } realWidth *= scale; realHeight *= scale; x = (windowW - realWidth)/2; y = (windowH - realHeight)/2; $(".swiper-container .swiper-slide").eq(i).find('img').css("width",realWidth); var w = (windowW-realWidth)/2; var h = (windowH-realHeight)/2; $(".swiper-container .swiper-slide").eq(i).css({"top":h, "left":w}); }); } $(".swiper-container").click(function(){ $(".swiper-container").hide() }) Swiper1 = new Swiper ('.swiper-container', { preventLinksPropagation : false, //拖动时阻止click事件 pagination: '.swiper-pagination', //下方圆点 slidesPerView: 1, //容器同时显示slides的数量 paginationClickable: true, //分页指示点可切换图片 observer: true, //图片删除修改时,自动初始化swiper speed: 500, autoplayDisableOnInteraction: false, //用户操作后重启autoplay }); function change(index){ //点击缩略图展示相关图片 $(".swiper-container").show() Swiper1.slideTo(index,100,false); }
效果如下
图片可以左右滑动相关文章推荐
- 如何在App中实现朋友圈功能之四在朋友圈中添加发送图片功能——箭扣科技Arrownock
- [置顶] 【Android】Android开发启动app弹出一张广告图片,Dialog可以查看大图,查看某个图片功能
- 【Android】Android开发启动app弹出一张广告图片,Dialog可以查看大图,查看某个图片功能
- Win7画图工具在查看图片方面有哪些功能如何使用
- Android相机开发(一)之预览拍照查看图片基本功能的实现
- 图片放大时实现鼠标拖动查看完整图片功能
- js canvas实现放大镜查看图片功能
- 前端实现多图片上传查看功能(带UI实现)
- 实现“鼠标移入仿购物网站图片查看细节”功能
- 实现查看网络图片功能
- ecshop后台广告列表中增加图片查看功能
- Android 实验——实现查看网络图片功能
- 04-UIScrollView分页功能实现循环查看图片
- javascript实现查看html网页放大图片功能
- 病人管理系统中查看管理图片功能的实现
- MessageDisplayKit 一个类似微信App的IM应用,拥有发送文字、图片、语音、视频、地理位置消息,管理本地通信录、分享朋友圈、漂流交友、摇一摇和更多有趣的功能。
- Android Camera开发系列(下)——自定义Camera实现拍照查看图片等功能
- 查看图片(前进后退)功能
- Win8.1系统中画图工具查看图片功能汇总介绍
- 图片查看功能封装