jQuery實(shí)現(xiàn)查看圖片功能
本文實(shí)例為大家分享了jQuery實(shí)現(xiàn)查看圖片的具體代碼,供大家參考,具體內(nèi)容如下
HTML
<!-- 放縮略圖的div -->
<div class="sl">
<img src="images/1.jpg" />
<img src="images/2.jpg" />
<img src="images/3.jpg" />
</div>
<!-- 實(shí)現(xiàn)關(guān)燈的div -->
<div class="gd"></div>
<div class="yt">
<!-- 左翻按鈕 -->
<div class="left">
<img src="images/left.png" alt="" width="100">
</div>
<div class="tp">
<!-- 展示原圖 -->
<img src="images/1.jpg" class="show" />
<!--放開(kāi)始和結(jié)束圖片的盒子 -->
<div class="ss" style="display: none;">
<img src="images/start.png" alt="" width="50" class="start">
</div>
</div>
<!-- 右翻按鈕 -->
<div class="right">
<img src="images/right.png" alt="" width="100">
</div>
</div>
CSS
html,body{
padding: 0;
margin: 0;
}
.sl img {
width: 300px;
}
.gd {
background-color: rgba(0, 0, 0, 0.7);
position: absolute;
z-index: 900;
display: none;
top: 0;
left: 0;
}
.sl {
position: absolute;
z-index: 888;
display: flex;
flex-wrap: wrap;
justify-content: center;
}
.sl>img {
width: 25%;
}
.yt {
z-index: 990;
position: absolute;
display: none;
left: 500px;
top: 200px;
}
.tp {
margin: 0 20px;
}
.yt>div {
display: inline-block;
}
.left,
.right {
position: relative;
top: -110px;
cursor: pointer;
}
.ss {
position: relative;
width: 50px;
height: 50px;
left: 270px;
}
.start {
z-index: 990;
position: absolute;
}
JS
var max = $(".sl img").length;
$(function (e) {
var width = $(window).width();
var height = $(window).height();
$(".gd").css({
"height": height,
"width": width
});
//左翻按鈕動(dòng)畫(huà)
$(".left").hover(
function () {
$(this).animate({
"left": "-10"
});
},
function () {
$(this).animate({
"left": "0"
});
}
);
//右翻按鈕動(dòng)畫(huà)
$(".right").hover(
function () {
$(this).animate({
"right": "-10"
});
},
function () {
$(this).animate({
"right": "0"
});
}
);
//被點(diǎn)擊的縮略圖
$(".sl>img").click(function (e) {
$(".gd").show(500);
$(".yt").fadeIn(800);
var index = $(this).index(); //當(dāng)前被點(diǎn)擊圖片的索引
$(".tp>img").attr("src", "images/" + (index + 1) + ".jpg");
//左翻
$(".left").click(function (e) {
if (index - 1 < 0) {
index = max - 1;
} else {
index = index - 1;
}
$(".tp>img").attr("src", "images/" + (index + 1) + ".jpg");
});
//右翻
$(".right").click(function (e) {
if (index == max - 1) {
index = 0;
} else {
index = index + 1;
}
$(".tp>img").attr("src", "images/" + (index + 1) + ".jpg");
});
//隱藏和顯示播放按鈕
$(".tp").hover(
function () {
$(".ss").fadeIn(500);
$(this).animate({
"opacity": "0.7"
}, 700);
},
function () {
$(".ss").fadeOut(500);
$(this).animate({
"opacity": "1"
}, 700);
}
);
//點(diǎn)擊開(kāi)始播放 再次點(diǎn)擊結(jié)束播放
let flag = true;
$(".start").click(function () {
if (flag == true) {
time = setInterval(function () {
if (index == max - 1) {
index = 0;
} else {
index = index + 1;
}
$(".tp>img").attr("src", "images/" + (index + 1) + ".jpg");
}, 2000);
flag = false;
$(".start").attr("src", "images/stop.png");
} else {
clearInterval(time);
flag = true;
$(".start").attr("src", "images/start.png");
}
});
let h = $(".tp>img").height();
$(".ss").css({
"top": -h / 2 - 25
});
//隱藏關(guān)燈效果
$(".gd").click(function () {
$(".gd").hide(800);
$(".yt").fadeOut(500);
});
});
});
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
jQuery插件FusionCharts實(shí)現(xiàn)的MSBar2D圖效果示例【附demo源碼】
這篇文章主要介紹了jQuery插件FusionCharts實(shí)現(xiàn)的MSBar2D圖效果,結(jié)合實(shí)例形式分析了jQuery使用FusionCharts插件結(jié)合x(chóng)ml數(shù)據(jù)載入實(shí)現(xiàn)繪制MSBar2D圖的相關(guān)實(shí)現(xiàn)技巧,并附帶demo源碼供讀者下載,需要的朋友可以參考下2017-03-03
jquery實(shí)現(xiàn)背景跟隨鼠標(biāo)滑動(dòng)導(dǎo)航
這篇文章主要為大家詳細(xì)介紹了jquery背景跟隨鼠標(biāo)滑動(dòng)導(dǎo)航,特別美觀,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2015-11-11
方便實(shí)用的jQuery checkbox復(fù)選框全選功能簡(jiǎn)單實(shí)例
這篇文章介紹了jQuery checkbox復(fù)選框全選功能的代碼實(shí)例,有需要的朋友可以參考一下2013-10-10
jQuery中each循環(huán)的跳出和結(jié)束實(shí)例
下面小編就為大家?guī)?lái)一篇jQuery中each循環(huán)的跳出和結(jié)束實(shí)例。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-08-08
jquery實(shí)現(xiàn)帶復(fù)選框的表格行選中刪除時(shí)高亮顯示
在實(shí)際的應(yīng)用中可能會(huì)出現(xiàn)表格中帶復(fù)選框的,刪除時(shí),將復(fù)選框所在的行的記錄刪除。在這的地方,可以加個(gè)特效,單擊某行的同時(shí)將該行的復(fù)選框選中,該行的背景色也高亮顯示2013-08-08
jq stop()和:is(:animated)的用法及區(qū)別(詳解)
下面小編就為大家?guī)?lái)一篇jq stop()和:is(:animated)的用法及區(qū)別(詳解)。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-02-02

