使用Jquery Viewer 展示圖片資訊

木有暱稱發表於2019-01-17

<!DOCTYPE html>
<html lang=”en”>
<head>
<meta charset=”utf-8″>
<meta http-equiv=”x-ua-compatible” content=”ie=edge”>
<meta name=”viewport” content=”width=device-width, initial-scale=1, shrink-to-fit=no”>
<title>Viewer.js</title>
<link rel=”stylesheet” href=”https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css”>
<link rel=”stylesheet” href=”../dist/viewer.css”>
</head>
<body>
<div class=”container”>
<h1>Show a viewer dynamically on click a button</h1>
<button type=”button” class=”btn btn-primary” id=”button” onclick=”showimages();”>
Launch the demo
</button>
</div>

 <ul id=”viewer” class=”ulline”>

<li><img src=”1.jpg” data-original=”大圖地址”></li>

<li><img src=”2.jpg” data-original=”大圖地址”></li>

<li><img src=”3.jpg” data-original=”大圖地址”></li>

<li><img src=”4.jpg” data-original=”大圖地址”></li>

</ul>

<script src=”https://code.jquery.com/jquery-3.3.1.slim.min.js”></script>
<script src=”https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.bundle.min.js”></script>
<script src=”../dist/viewer.js”></script>
<script>

function showimages(){

var viewer = new Viewer(document.getElementById(“viewer”), {
url(image) {
return image.attributes[“data-original”].value;//設定展示大圖的地址
},
hidden: function () {
viewer.destroy();
},
viewed() {
viewer.zoomTo(1);//設定顯示百分比  1標示百分之100  0標示百分之0
},
});
viewer.show();

}
</script>
</body>
</html>

 

外掛下載地址 https://files.cnblogs.com/files/xiaoxiangpaou/viewerjs-master.zip

相關文章