var mapscroll = true function getImageDimensions(imgSrc) { var img = new Image(); img.src = imgSrc; // 确保图片加载完成 img.onload = function() { var width = img.width; var height = img.height; // console.log("Width: " + width + ", Height: " + height); }; return {"w": img.width, 'h': img.height}; } function mapFn(data,titleStr,n){ $(".searchProductList").attr("data-exactQuery",0) var nList = n>=9?(n+1):"0"+(n+1) if(titleStr && titleStr.length>0){ var productNum = titleStr.split(":")[1] if(productNum && productNum.length>0){ setTimeout(function(){ ajaxFn({ keyword:productNum, exactQuery:0 //exactQuery,是否精确查询:0=模糊,1=精确,默认为0 }) }) $(".proView .ulItem").each(function(){ var _this = $(this) if (_this.css('display') === 'block') { _this.find("ul li").removeClass("active").eq(n).addClass("active") } }) if(mapscroll){ mapscroll = true setTimeout(function(){ $('body,html').animate({ scrollTop: $(".searchProductList").offset().top-$(window).height()/2 }, 500) },10) } } // 拓扑图关联产品列表 $(".hotProList .proItem").removeClass("active").each(function(){ var _this = $(this) if(_this.find(".serialNumber").text().trim()==nList){ _this.addClass("active") } }) } } var appDt = { appPic:function(imgObj={}){ $(".imgItem").each(function(){ var imgs = $(this).find("img") var imgsData = { w:imgObj.w || $(this).find("img").width(), h:imgObj.h || $(this).find("img").height() } var dataInfo = getImageDimensions(imgs.attr("src")) $(this).find("img").attr("datawidth",imgsData.w).attr("data-height",imgsData.h).attr("data-w",dataInfo.w).attr("data-h",dataInfo.h) var scaleNum = imgsData.w/dataInfo.w $(this).find(".mapList").each(function(){ var _this = $(this) var coordsStr = _this.attr("data-coords").split(",").map(function(i){return i*scaleNum/(646/dataInfo.w)}).join(",") _this.attr('coords',coordsStr) _this.hover(function(){ var _coordsStr = coordsStr.split(",") $(".appCircuitBox .imgMapBg").css({ "width":_coordsStr[2]-_coordsStr[0]+"px", "height":_coordsStr[3]-_coordsStr[1]+"px", "left":_coordsStr[0]+"px", "top":_coordsStr[1]+"px", "display":"block" }).attr("data-title",_this.attr("data-title")).attr("data-index",_this.attr("data-index")) },function(){ $(".appCircuitBox .imgMapBg").hide(); }) }) }) $(".appCircuitBox .imgMapBg").hover(function(){$(this).show()},function(){$(this).hide()}) $(".appCircuitBox .imgMapBg").click(function(){ var _title = $(this).attr("data-title") var _index = $(this).attr("data-index") if(_title && _title.length>0){ mapFn("",_title,_index) } }) }, faysFn:function(){ $(".app2ImgBox_in .btnTap").on("click",function(){ $(".app2ImgBox").addClass("active") var _index = $(this).index() $(this).addClass("active").siblings().removeClass("active") $(".app2ImgBox_in .txtBox .item").removeClass("active").eq(_index).addClass("active") }) $(".app2ImgBox_in .btnScroll").on("click",function(){ $('body,html').animate({ scrollTop: $(".appCircuitBox").offset().top-80 }, 500) }) } } $(function(){ var itemImgObj = {w:null,h:null} appDt.appPic(itemImgObj) appDt.faysFn() $('.product_center .center_box .le_box .tent1').click(function () { setTimeout(function(){ itemImgObj.w = $(".appCircuitBox .imgItem img").width() itemImgObj.h = $(".appCircuitBox .imgItem img").height() appDt.appPic(itemImgObj) },1000) }) $(".appTab .item").on("click",function(){ var _index = $(this).index() $(this).addClass("active").siblings().removeClass("active") $(".appCircuitBox .imgsBox .imgItem").removeClass("active").eq(_index).addClass("active") $(".proView .ulItem").hide().eq(_index).show() setTimeout(function(){ $(".ulItem.wdz-scroll").mCustomScrollbar({ scrollButtons: { enable: false } }) },10) }) //产品展示 $(".proView ul li").click(function(){ var _index = $(this).index() $(this).addClass("active").siblings().removeClass("active") var titleStr = $(this).attr("data-str") if(titleStr && titleStr.length>0){ ajaxFn({ keyword:titleStr, exactQuery:0 // exactQuery,是否精确查询:0=模糊,1=精确,默认为0 }) } }) //选型推荐 v2 $(".proView .hotProList .proItem").on("click",function(){ $(".searchProductList").attr("data-exactQuery",0) var titleStr = $(this).attr("data-str") $(this).addClass("active").siblings().removeClass("active") if(titleStr && titleStr.length>0){ setTimeout(function(){ ajaxFn({ keyword:titleStr, exactQuery:0 // exactQuery,是否精确查询:0=模糊,1=精确,默认为0 }) }) } }) })