前言
最近涉及一个移动端项目
需要把其中的图片变成可预览的图片
听学弟说 可以利用viewer进行实现
首先
我们需要做的就是先写一个简单demo
先实现其中的效果
实现效果
在这里插入图片描述
代码
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <link rel="stylesheet" href="https://unpkg.com/bootstrap@4/dist/css/bootstrap.min.css" crossorigin="anonymous"> <link rel="stylesheet" href="./css/viewer.css"> </head> <body> <!--./images/thumbnails/tibet-1.jpg--> <div id="galley"> <ul id="images1" class="img-list"> <li> <img src="./images/thumbnails/tibet-1.jpg"/> </li> <li> <img src="./images/thumbnails/tibet-1.jpg"/> </li> <li> <img src="./images/thumbnails/tibet-1.jpg"/> </li> <li> <img src="./images/thumbnails/tibet-1.jpg"/> </li> </ul> <!--二--> <!-- <ul id="image2" class="img-list"> <li> <img src="./images/thumbnails/tibet-1.jpg" data-imgurl="./images/thumbnails/tibet-1.jpg"/> </li> <li> <img src="./images/thumbnails/tibet-1.jpg" data-imgurl="./images/thumbnails/tibet-1.jpg"/> </li> <li> <img src="./images/thumbnails/tibet-1.jpg" data-imgurl="./images/thumbnails/tibet-1.jpg"/> </li> <li> <img src="./images/thumbnails/tibet-1.jpg" data-imgurl="./images/thumbnails/tibet-1.jpg"/> </li> </ul>--> </div> </body> </html> <script src="https://unpkg.com/jquery@3/dist/jquery.slim.min.js" crossorigin="anonymous"></script> <script src="https://unpkg.com/bootstrap@4/dist/js/bootstrap.bundle.min.js" crossorigin="anonymous"></script> <script src="./js/viewer.js"></script> <script> window.onload = function(){ var viewer = new Viewer(document.getElementById('galley'), {}); // var viewer = new Viewer(document.getElementById('image2'), { url: 'data-imgurl' }); } </script>
步骤
看一下效果预览
点击的时候就可以进行一个效果的预览操作了
同样 三步走
第一步引入
第二步注意结构
第三步效果演示
</div> <div class="col-lg-12"> <div id="allmap"> <img src="images/867.png" data-imgurl="images/867.png" alt="" style="width: 100%"> </div> </div> </div> </div> <!--公共尾部--> <div class="footer"></div> </body> <script src="js/main.js"></script> <script src="js/aos.js"></script> <script src="js/viewer.js"></script> <script> window.onload = function(){ var viewer = new Viewer(document.getElementById('allmap'), {}); // var viewer = new Viewer(document.getElementById('image2'), { url: 'data-imgurl' }); } //DOM加载完成之后执行函数