html 缩略图点击预览,jQuery图片相册点击缩略图弹出大图预览特效

js代码

var img_index = 0;

var img_src = "";

$(function() {

//计算居中位置

var mg_top = ((parseInt($(window).height()) - parseInt($(".photo-div").height())) / 2);

$(".photo-div").css({

"margin-top": "" + mg_top + "px"

});

//关闭

$(".photo-close").click(function() {

$(".photo-mask").hide();

$(".photo-panel").hide();

});

//下一张

$(".photo-panel .photo-div .arrow-next").click(function() {

img_index++;

if(img_index >= $(".demo li img").length) {

img_index = 0;

}

img_src = $(".demo li img").eq(img_index).attr("src");

photoView($(".demo li img"));

});

//上一张

$(".photo-panel .photo-div .arrow-prv").click(function() {

img_index--;

if(img_index < 0) {

img_index = $(".demo li img").length - 1;

}

img_src = $(".demo li img").eq(img_index).attr("src");

photoView($(".demo li img"));

});

//如何调用?

$(".demo li img").click(function() {

$(".photo-mask").show();

$(".photo-panel").show();

img_src = $(this).attr("src");

img_index = $(this).index();

photoView($(this));

});

});

//自适应预览

function photoView(obj) {

if($(obj).width() >= $(obj).height()) {

$(".photo-panel .photo-div .photo-img .photo-view-h").attr("class", "photo-view-w");

$(".photo-panel .photo-div .photo-img .photo-view-w img").attr("src", img_src);

} else {

$(".photo-panel .photo-div .photo-img .photo-view-w").attr("class", "photo-view-h");

$(".photo-panel .photo-div .photo-img .photo-view-h img").attr("src", img_src);

}

//此处写调试日志

console.log(img_index);

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值