jQuery 帶炫酷輪播圖效果的Lightbox彈出層插件 只要一句代碼輕鬆實現功能

     最近在做手機瀏覽器端的一個功能,就是用過點擊圖片,然後顯示所有圖片相冊可以切換查看功能。但是自己寫的話感覺是很麻煩,今天給他就介紹一款jQuery插件,就一句代碼輕鬆實現,兼容PC、H5端。

1:在頁面引入相關JS、樣式文件

<link href="css/popup-lightbox.css" rel="stylesheet" />
  <link href="css/animate.css" rel="stylesheet" />
  <link href="css/demo.css" rel="stylesheet" />
  <link href="http://cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
  <script src="js/jquery-1.9.1.min.js"></script>
  <script src="js/jquery.popup.lightbox.js"></script>

  1.1 popup-lightbox.css文件

/*   Project: Popup Lightbox 
 *   Author: Asif Mughal
 *   URL: www.codehim.com
 *   License: MIT License
 *   Copyright (c) 2019 - Asif Mughal
 */
 
/* File: popup-lightbox.css */

.lightbox {
	position: fixed;
	background: rgba(0, 0, 0, 0.90);
	display: none;
	z-index: 100;
}

.lightbox .img-show {
	position: absolute;
	height: 100%;
	width: 100%;
	box-sizing: border-box;
	text-align: center;
}

.img-caption {
	background: rgba(0, 0, 0, 0.3);
	padding: 10px;
	position: absolute;
	bottom: 0;
	display: block;
	z-index: 101;
	color: #fff;
	text-shadow: 1px 0.4px rgba(0, 0, 0, 0.5);
	width: 100%;
	box-sizing: border-box;
}

.lightbox .btn-close {
	position: absolute;
	top: 10px;
	right: 10px;
	width: 32px;
	height: 32px;
	border: 1px solid #fff;
	background: rgba(255, 255, 255, 0.5);
	border-radius: 50%;
	text-align: center;
	font-size: 18pt;
	z-index: 101;
	cursor: pointer;
}

.lightbox .btn-close:hover {
	background: #fff;
}

.lightbox .lightbox-status {
	position: absolute;
	top: 20px;
	left: 20px;
	color: #fff;
	font-size: 14px;
	z-index: 101;
}

.img-show img {
	width: 100%;
	height: auto;
	position: absolute;
	display: block;
	top: 0;
	bottom: 0;
	margin: auto;
}


/* Next and Previous Buttons */

.btn-prev,
.btn-next {
	width: 32px;
	height: 100px;
	background: rgba(0, 0, 0, 0.30);
	cursor: pointer;
	position: absolute;
	top: 50%;
	margin-top: -50px;
	z-index: 101;
	border: 0;
	font-family: FontAwesome;
	color: #fff;
	color: rgba(255, 255, 255, 0.6);
	font-size: 18pt;
	border-radius: 5px;
}

.btn-prev:hover,
.btn-next:hover {
	background: rgba(0, 0, 0, 0.7);
	color: #fff;
	transition: .4s;
	-webkit-transition: .4s;
	-moz-transition: .4s;
	-ms-transition: 0.4s;
	-o-transition: .4s;
}

.btn-prev {
	left: 5px;
}

.btn-next {
	right: 5px;
}

.btn-prev:before {
	content: "\f104";
}

.btn-next:before {
	content: "\f105";
}

@media only screen and ( min-width: 680px) {
	.lightbox {
		border-radius: 5px;
		box-shadow: 5px 5px 15px rgba(0, 0, 0, 0.5);
	}
}

2 該Lightbox彈出層的HTML結構如下。

<div class="img-container">
         <img src="images/1.jpg" alt="第一張圖片" />
         <img src="images/2.jpg" alt="這是第二張"/>
         <img src="images/3.jpg" alt="三張"/>
         <img src="images/4.jpg" alt="最後一張" />
      </div>

3:頁面加載完成執行一句代碼

$(document).ready(function(){

	$(".img-container").popupLightbox();
})

效果圖如下:

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章