php图片点击查看大图,jQuery点击小图看大图,大图查看内容详情所有图片

本文介绍如何使用jQuery创建一个简单的图片查看器,通过点击缩略图,可以显示大图并实现左右滑动浏览内容详情。通过HTML结构、CSS样式和jQuery代码展示了如何实现实时加载大图,以及控制显示和隐藏的逻辑。
摘要由CSDN通过智能技术生成

jQuery点击小图看大图,大图查看内容详情所有图片:

html代码如下:

×

<

>

CSS代码如下:

* {

margin:0;

padding:0;

}

body {

overflow-x:hidden;

}

.gallery {

width:950px;

margin:10px auto;

border:1px solid #000;

overflow:hidden;

padding:20px;

border-radius:15px;

box-shadow:1px 2px 3px black;

}

.gallery ul {

list-style:none;

}

.gallery ul li {

float:left;

width:160px;

height:86px;

margin-right:30px;

margin-bottom:30px;

cursor:pointer;

padding:5px;

}

.BLACKCOVER {

width:100%;

height:100%;

background-color:black;

opacity:0.6;

position:fixed;

top:0;

left:0;

display:none;

}

.bigShow {

position:absolute;

top:38.2%;

left:50%;

width:560px;

height:300px;

padding:20px;

background:white url(juhua.gif) no-repeat center center;

margin-top:-150px;

margin-left:-280px;

box-shadow:1px 2px 3px black;

border-radius:15px;

display:none;

}

.bigShow span.close {

position:absolute;

width:30px;

height:30px;

background-color:black;

color:white;

border:1px solid #000;

right:-15px;

top:-15px;

border-radius:50%;

font-size:30px;

line-height:30px;

text-align:center;

cursor:pointer;

}

.bigShow img {

display:none;

}

.bigShow span.leftBtn {

position:absolute;

width:60px;

height:60px;

top:50%;

left:-30px;

margin-top:-30px;

background-color:#38C9C3;

font-size:60px;

text-align:center;

line-height:60px;

border-radius:50%;

cursor:pointer;

}

.bigShow span.rightBtn {

position:absolute;

width:60px;

height:60px;

top:50%;

right:-30px;

margin-top:-30px;

background-color:#38C9C3;

font-size:60px;

text-align:center;

line-height:60px;

border-radius:50%;

cursor:pointer;

}jquery代码如下:

$(document).ready(function() {

var $BLACKCOVER = $(".BLACKCOVER");

var $bigShow = $(".bigShow");

var $bigImg = $bigShow.children("img");

var $leftBtn = $(".leftBtn");

var $rightBtn = $(".rightBtn");

var $lis = $(".gallery ul li");

var nowimg = 0;

$(".gallery>ul>li").click(function() {

//让大黑布展示:

$BLACKCOVER.fadeIn();

//让大图显示

$bigShow.show();

var URL = $(this).attr("data-large");

nowimg = $(this).index();

$.get(URL, function(data) {

//图片已经完整请求之后,做的事情!

//请求之后做的事情

//里面不用data参数。

$bigImg.attr("src", URL);

$bigImg.fadeIn();

});

//让大图的src,变成你点击的li里面的data-large属性:

});

//关闭业务

$(".close , .BLACKCOVER").click(function() {

$BLACKCOVER.fadeOut();

$bigShow.hide();

$bigImg.hide();

});

$(".rightBtn").click(function() {

nowimg++;

if (nowimg > 9) {

nowimg = 0;

}

$bigShow.animate({

"left": -560

}, 400, function() {

$bigImg.hide();

$(this).css("left", 3000);

$(this).animate({

"left": "50%"

}, 400);

//请求新的图片

var URL = $lis.eq(nowimg).attr("data-large");

$.get(URL, function(data) {

//图片已经完整请求之后,做的事情!

//请求之后做的事情

//里面不用data参数。

$bigImg.show();

$bigImg.attr("src", URL);

});

});

});

});

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值