//accordion box if($('.accordion-box').length){ $(".accordion-box").on('click', '.acc-btn', function() { var outerbox = $(this).parents('.accordion-box'); var target = $(this).parents('.accordion'); if($(this).hasclass('active')!==true){ $(outerbox).find('.accordion .acc-btn').removeclass('active'); } if ($(this).next('.acc-content').is(':visible')){ return false; }else{ $(this).addclass('active'); $(outerbox).children('.accordion').removeclass('active-block'); $(outerbox).find('.accordion').children('.acc-content').slideup(300); target.addclass('active-block'); $(this).next('.acc-content').slidedown(300); } }); } //tabs box if($('.tabs-box').length){ $('.tabs-box .tab-buttons .tab-btn').on('click', function(e) { e.preventdefault(); var target = $($(this).attr('data-tab')); if ($(target).is(':visible')){ return false; }else{ target.parents('.tabs-box').find('.tab-buttons').find('.tab-btn').removeclass('active-btn'); $(this).addclass('active-btn'); target.parents('.tabs-box').find('.tabs-content').find('.tab').fadeout(0); target.parents('.tabs-box').find('.tabs-content').find('.tab').removeclass('active-tab animated fadein'); $(target).fadein(0); $(target).addclass('active-tab animated fadein'); } }); } function imgshow(outerdiv, innerdiv, bigimg, _this){ var src = _this.attr("src");//获取当前点击的pimg元素中的src属性 $(bigimg).attr("src", src);//设置#bigimg元素的src属性 /*获取当前点击图片的真实大小,并显示弹出层及大图*/ $("").attr("src", src).load(function(){ var windoww = $(window).width();//获取当前窗口宽度 var windowh = $(window).height();//获取当前窗口高度 var realwidth = this.width;//获取图片真实宽度 var realheight = this.height;//获取图片真实高度 var imgwidth, imgheight; var scale = 0.8;//缩放尺寸,当图片真实宽度和高度大于窗口宽度和高度时进行缩放 if(realheight>windowh*scale) {//判断图片高度 imgheight = windowh*scale;//如大于窗口高度,图片高度进行缩放 imgwidth = imgheight/realheight*realwidth;//等比例缩放宽度 if(imgwidth>windoww*scale) {//如宽度扔大于窗口宽度 imgwidth = windoww*scale;//再对宽度进行缩放 } } else if(realwidth>windoww*scale) {//如图片高度合适,判断图片宽度 imgwidth = windoww*scale;//如大于窗口宽度,图片宽度进行缩放 imgheight = imgwidth/realwidth*realheight;//等比例缩放高度 } else {//如果图片真实高度和宽度都符合要求,高宽不变 imgwidth = realwidth; imgheight = realheight; } $(bigimg).css("width",imgwidth);//以最终的宽度对图片缩放 var w = (windoww-imgwidth)/2;//计算图片与窗口左边距 var h = (windowh-imgheight)/2;//计算图片与窗口上边距 $(innerdiv).css({"top":h, "left":w});//设置#innerdiv的top和left属性 $(outerdiv).fadein("fast");//淡入显示#outerdiv及.pimg }); $(outerdiv).click(function(){//再次点击淡出消失弹出层 $(this).fadeout("fast"); }); } $(function(){ $(".pimg").click(function(){ var _this = $(this); imgshow("#outerdiv", "#innerdiv", "#bigimg", _this); }); });