var ImagePreview = { default_params: {}, init: function(a) { if (a) { $.extend(this.default_params, a) } console.log(a); ip_global_img_list = []; var b = this.default_params.id; if (typeof b == "string") { if ((ip_global_img_list = $("#" + b).find("img")).length == 0) { return } } else { if (typeof b == "object" && b != null) { ip_global_img_list = $(b) } } // console.log(a); this.fnGenerateHtml(); this.fnBindEvent(ip_global_img_list) }, fnBindEvent: function(a) { if (a.length == 0) { return } $(a).on("click", this.onClickEvent); this.onDragEvent($("#ip-img-preview")); $("#ip-img-preview").on("mousewheel DOMMouseScroll", this.onMouseScrollEvent); $("#ip-img-floatshadow").on("click", function() { $("#ip-img-preview").hide(); $("#ip-left").hide(); $("#ip-right").hide(); $("#ip-img-floatshadow").hide(); $("#ip-img-preview").attr("src", "") }); $("#ip-left").hover(this.fnMouseOver, this.fnMouseOut).click(this.fnPrev); $("#ip-right").hover(this.fnMouseOver, this.fnMouseOut).click(this.fnNext) }, fnGenerateHtml: function() { $("body").append( '' ); $("body").append( '' ) }, fnMouseOver: function() { // $(this).css("background", "rgb(134, 134, 134)"); // $(this).css("border", "1px solid rgb(111, 111, 111)") }, fnMouseOut: function() { $(this).css("background", ""); $(this).css("border", "") }, fnPrev: function() { if (typeof(ip_global_cur) == "number" && ip_global_cur > 0) { ImagePreview.fnReset(); $("#ip-img-preview").animate({ left: "49%" }, 100); $("#ip-img-preview").attr("src", ip_global_img_list[--ip_global_cur].src); $("#ip-img-preview").animate({ left: "50.5%" }, 100); $("#ip-img-preview").animate({ left: "50%" }, 100); ImagePreview.fnAdjustMaxWidth() } }, fnNext: function() { if (typeof(ip_global_cur) == "number" && ip_global_cur < ip_global_img_list.length - 1) { ImagePreview.fnReset(); $("#ip-img-preview").animate({ left: "51%" }, 100); $("#ip-img-preview").attr("src", ip_global_img_list[++ip_global_cur].src); $("#ip-img-preview").animate({ left: "49.5%" }, 100); $("#ip-img-preview").animate({ left: "50%" }, 100); ImagePreview.fnAdjustMaxWidth() } }, fnGetIndexOfCurImg: function(b) { for (var a = 0; a < ip_global_img_list.length; a++) { if ($(ip_global_img_list[a]).is(b)) { return a } } }, onClickEvent: function(a) { ImagePreview.fnReset(); $("#ip-img-preview").attr("src", $(this).attr("src")); ImagePreview.fnAdjustMaxWidth(); ip_global_cur = ImagePreview.fnGetIndexOfCurImg($(this)); $("#ip-img-floatshadow").fadeIn(); $("#ip-img-preview").fadeIn(); $("#ip-left").fadeIn(); $("#ip-right").fadeIn() }, fnAdjustMaxWidth: function() { var b = true; var a = $("#ip-img-preview").width(); if (a < $("#ip-img-preview").height()) { b = false; a = $("#ip-img-preview").height() } if (b && $(window).width() < a) { $("#ip-img-preview").css("width", "75%") } else { if (!b && $(window).height() < a) { $("#ip-img-preview").css("height", "75%") } } }, fnReset: function() { $("#ip-img-preview").css("left", "50%"); $("#ip-img-preview").css("top", "50%"); $("#ip-img-preview").css("width", ""); $("#ip-img-preview").css("height", "") }, onMouseScrollEvent: function(b) { b.preventDefault(); var a = b.originalEvent.wheelDelta || -b.originalEvent.detail; var c = Math.max(-1, Math.min(1, a)); if (c < 0) { $(this).width($(this).width() / 1.1); $(this).height($(this).height() / 1.1) } else { $(this).width($(this).width() * 1.1); $(this).height($(this).height() * 1.1) } }, onDragEvent: function(c) { c.bind("mousedown", d); function d(e) { if (e.button == 0) { gapX = e.clientX - c.offset().left; gapY = e.clientY - c.offset().top; $(document).bind("mousemove", a); $(document).bind("mouseup", b) } return false } function a(e) { c.css({ left: (e.clientX - gapX + c.width() / 2) + "px", top: (e.clientY - gapY + c.height() / 2) + "px" }); return false } function b() { $(document).unbind("mousemove", a); $(document).unbind("mouseup", b) } } };