$(function () { //裁剪填充 //needmf 是否需要maginleft值(偏移量) $.fn.cutFillAuto = function () { if (typeof (LayoutConverter) !== "undefined") { return; } var imgWidth, imgHeight, needmf, cb; return this.cutFill(imgWidth, imgHeight, needmf, cb, true); }; $.fn.cutFill = function (imgWidth, imgHeight, needmf, cb, isAuto) { var widthCopy = imgWidth; var heightCopy = imgHeight; var cutFillFuc = function (e, width, height, needmf) { if (e.attr("src") != "") { if (typeof widthCopy === "undefined") { width = e.width(); } if (typeof heightCopy === "undefined") { height = e.height(); } _cutFillInit(e, width, height, needmf); } } this.each(function () { var $this = $(this); //仅对不需要裁剪的图片进行处理, 目前拉升和等比在标签切换中没影响 故不做区分 var needCut = $this.hasClass("NoCutFill"); if (needCut) { return true; } if (isAuto) { if ($this.attr("init") != "ok") { return true; } if ($this.attr("autoFill") != "ok") { return true; } } var isReset = false; if (typeof widthCopy === "undefined" && typeof heightCopy === "undefined") { if ($this.attr("autoFill") == "ok") { $this.css("width", "").css("height", "").css("margin-left", "").css("margin-top", ""); isReset = true; } else { if (!isAuto) { $this.attr("autoFill", "ok"); } } } if (!isAuto) { $this.attr("init", "ok"); } if ($this[0].complete) { if (isReset) { var timeoutId = parseInt($this.attr("timeoutId")); if (timeoutId > 0) { clearTimeout(timeoutId); } timeoutId = setTimeout(function () { cutFillFuc($this, imgWidth, imgHeight, needmf); }, 100); $this.attr("timeoutId", timeoutId); } else { cutFillFuc($this, imgWidth, imgHeight, needmf); } } else { $this.on("load", function () { cutFillFuc($this, imgWidth, imgHeight, needmf); }); } if (typeof cb == "function") { cb($this); } }); return this; } _cutFillInit = function (img, imgWidth, imgHeight, needmf) { var $this = $(img); var width = parseInt(imgWidth); var height = parseInt(imgHeight); var realWidth = $this[0].naturalWidth; var realHeight = $this[0].naturalHeight; var halfIntWidth = width / 2; var halfIntHeight = height / 2; var vs = realWidth / realHeight; //缩略图比例240:160(等于1.5) if (vs >= 1.5) {//横图则固定高度 if (width > height * vs) { $this.css("width", width + "px").css("height", "auto").css("marginTop", (halfIntHeight - (halfIntWidth * parseInt(realHeight) / parseInt(realWidth))) + "px"); } else { if (needmf || typeof needmf == "undefined") { $this.css("width", "auto").css("height", height + "px").css("marginLeft", (halfIntWidth - (halfIntHeight * parseInt(realWidth) / parseInt(realHeight))) + "px"); } else { $this.css("width", "auto").css("height", height + "px"); } } } else {// if (height > width / vs) { $this.css("width", "auto").css("height", height + "px").css("marginLeft", (halfIntWidth - (halfIntHeight * parseInt(realWidth) / parseInt(realHeight))) + "px"); } else { $this.css("width", width + "px").css("height", "auto").css("marginTop", (halfIntHeight - (halfIntWidth * parseInt(realHeight) / parseInt(realWidth))) + "px"); } } } $.fn.FixFill = function (maxWidth, maxHeight, redirect, imgEle) { var w, h; if (imgEle) { w = imgEle.naturalWidth; h = imgEle.naturalHeight; } else { var img = new Image(); img.src = this.attr('src'); w = img.width; h = img.height; } var dst = {}; if (redirect == "x") { dst.width = maxWidth; dst.height = parseInt(maxWidth * h / w, 10); } else if (redirect == "y") { dst.height = maxHeight; dst.width = parseInt(maxHeight * w / h, 10); } else { if (w > h) { dst.width = maxWidth; dst.height = parseInt(maxWidth * h / w, 10); } else { dst.height = maxHeight; dst.width = parseInt(maxHeight * w / h, 10); } } return dst; } $.fn.disableDrag = function () { $(this).draggable("option", "disabled", true); } $.fn.enableDrag = function () { $(this).draggable("option", "disabled", false); } $.fn.disableResize = function () { $(this).resizable("option", "disabled", true); } $.fn.enableResize = function () { $(this).resizable("option", "disabled", false); } /*动画*/ $('.animated').smanimate(); /*商品*/ $("#home-product-all .w-label-tips .w-label-tips-item").on("mouseenter", function () { $(this).siblings().removeClass("current"); $(this).addClass("current"); $(this).prev(".w-label-tips-line").addClass("current"); $(this).next(".w-label-tips-line").addClass("current"); let $content = $("#home-product-all .w-label-content .w-label-content-item[data-area='" + $(this).attr("data-area") + "']"); $content.addClass("current").siblings().removeClass("current"); $content.find("img").cutFillAuto(); }); let callback_home_new_all = function () { let sv = $(".w-al-list"); let dur = parseInt("300"); sv.find(".w-al-unit").hover(function () { let totalHeight = $(this).height(); let h5Height = $(this).find(".w-al-title").height(); let descHeight = $(this).find(".w-al-desc").height(); let padTop = (totalHeight - h5Height - descHeight) / 2 + "px"; $(this).find(".w-al-text").stop().animate({ height: "100%" }, dur); $(this).find(".w-al-text h5").stop().animate({ paddingTop: padTop }, dur); }, function () { $(this).find(".w-al-text").stop().animate({ height: "34px" }, dur); $(this).find(".w-al-text h5").stop().animate({ paddingTop: "0px" }, dur); }); //裁减填充 //sv.find("img").cutFill(); } callback_home_new_all(); });