var _imgid =0;
var _dataid =0;
var _datahid =0;
// 相册
$('.y_tuku_ul ul.y_tuku_ul_tu li').on('click',function(){
// 索引第几张图片
_imgid = $(this).index();
_dataid = $(this).attr('data-id');
_datahid = $(this).attr('data-hid');
lpindex_xc(_imgid);
})
function lpindex_xc(imgid){
$.post('/json/albumlist',{album_id:_dataid,hid:_datahid,csrf_token_f:csrfToken},function (data) {
var data=data.data;
var html = '';
html+= '
';
html+= '';
html+= '
';
// html+= '
';
html+= '
';
if(data.length != 1){
html+= '
';
html+= '
';
}
html+= '
';
$.each(data,function(key,val){
html+= '
';
html+= '
';
html+= '
';
// html+= '
';
html+= '
';
html+= '
';
});
html+= '
';
html+= '
';
html+= '
';
if(data.length != 1){
html+= '';
// html+= '
'+data[0].title+'
';
html+= '
';
html+= '
';
html+= '
';
html+= '
';
html+= '
';
$.each(data,function(key,val){
html+= '
';
// html+= '

';
html+= '

';
html+= '
';
});
html+= '
';
html+= '
';
html+= '
';
html+= '
';
}
$('.pc-slide').html(html);
$('.pc-slide').show();
var _width = $('.preview').innerWidth();
$('.preview').css('margin-left',-_width/2);
$('.preview').show();
$('.preview .swiper-wrapper .swiper-slide').eq(imgid).addClass('active-nav'); //默认选中
// 放大功能
function zoomImg(o) {
var zoom = parseInt(o.style.zoom, 10) || 100;
zoom += event.wheelDelta / 12; //可适合修改
// console.log(zoom);
if (zoom < 310 && zoom > 50 ) o.style.zoom = zoom + '%';
}
$(document).ready(function() {
$(".view .swiper_box img").bind("mousewheel",
function() {
zoomImg(this);
return false;
});
});
// $(".pc_slide_fd").on('click',function(){
// var style = $('.view .swiper-slide-active .swiper_box img').attr('style');
// console.log(style);
// $('.view .swiper-slide-active .swiper_box img').css('zoom','100%');
// })
$(".view .swiper_box img").dblclick(function(){
$(this).css('zoom','100%');
});
var viewSwiper = new Swiper('.view .swiper-container', {
onlyExternal : true,
centeredSlides : true,
initialSlide :imgid,
onSlideChangeStart: function() {
updateNavPosition(imgid);
}
})
$('.view .arrow-left,.preview .arrow-left').on('click', function(e) {
$('.view .swiper_box img').css('zoom','100%');
e.preventDefault()
if (viewSwiper.activeIndex == 0) {
viewSwiper.slideTo(viewSwiper.slides.length - 1, 1000);
return
}
viewSwiper.slidePrev()
})
$('.view .arrow-right,.preview .arrow-right').on('click', function(e) {
$('.view .swiper_box img').css('zoom','100%');
e.preventDefault()
if (viewSwiper.activeIndex == viewSwiper.slides.length - 1) {
viewSwiper.slideTo(0, 1000);
return
}
viewSwiper.slideNext()
})
var previewSwiper = new Swiper('.preview .swiper-container', {
//visibilityFullFit: true,
slidesPerView: 'auto',
allowTouchMove: false,
onTap: function() {
viewSwiper.slideTo(previewSwiper.clickedIndex)
$('.view .swiper_box img').css('zoom','100%');
}
})
function updateNavPosition(imgid) {
if(imgid == 0){
$('.preview .active-nav').removeClass('active-nav')
var activeNav = $('.preview .swiper-slide').eq(viewSwiper.activeIndex).addClass('active-nav');
if (!activeNav.hasClass('swiper-slide-visible')) {
if (activeNav.index() > previewSwiper.activeIndex) {
var thumbsPerNav = Math.floor(previewSwiper.width / activeNav.width()) - 1
previewSwiper.slideTo(activeNav.index() - thumbsPerNav)
} else {
previewSwiper.slideTo(activeNav.index())
}
}
}
}
$('.pc_slide_gb').on('click',function(){
$('.pc-slide').hide();
$('.pc-slide').html('');
})
imgid=0;
})
}