jQuery實(shí)現(xiàn)查看圖片功能
更新時(shí)間:2020年12月01日 09:22:56 作者:從入門to入萬
這篇文章主要為大家詳細(xì)介紹了jQuery實(shí)現(xiàn)查看圖片,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
本文實(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" />
<!--放開始和結(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)畫
$(".left").hover(
function () {
$(this).animate({
"left": "-10"
});
},
function () {
$(this).animate({
"left": "0"
});
}
);
//右翻按鈕動(dòng)畫
$(".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)擊開始播放 再次點(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);
});
});
});
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
使用jQuery實(shí)現(xiàn)的擲色子游戲動(dòng)畫效果
大家一定都玩過擲色子的游戲,今天我給大家分享的是如何使用jQuery來實(shí)現(xiàn)擲色子的動(dòng)畫效果,通過jQuery的animate()自定義動(dòng)畫函數(shù)并結(jié)合CSS背景圖片切換實(shí)現(xiàn)的動(dòng)畫效果2014-03-03
jquery之empty()與remove()區(qū)別說明
要用到移除指定元素的時(shí)候,發(fā)現(xiàn)empty()與remove([expr])都可以用來實(shí)現(xiàn)??勺屑?xì)觀察效果的話就可以發(fā)現(xiàn)。2010-09-09
jquery實(shí)現(xiàn)簡易的移動(dòng)端驗(yàn)證表單
本文給大家匯總介紹了幾個(gè)常用的jquery實(shí)現(xiàn)簡易的移動(dòng)端驗(yàn)證表單,非常的實(shí)用,有需要的小伙伴可以進(jìn)來參考下。2015-11-11
jquery 設(shè)置元素相對(duì)于另一個(gè)元素的top值(實(shí)例代碼)
在jquery中offset().top是相對(duì)于body來說的,另外在設(shè)置top值的時(shí)候要找到與該元素最近的有相對(duì)值的元素2013-11-11
jquery.simple.tree插件 更簡單,兼容性更好的無限樹插件
在這里介紹一款小巧,功能強(qiáng)大,能拖拽,支持異步,且兼容性更高的jquery Tree插件2010-09-09

