document.addEventListener("touchstart", function(){}, true); var $$ = document.querySelectorAll.bind(document); Element.prototype.on = Element.prototype.addEventListener; Element.prototype.off = Element.prototype.removeEventListener; var ForEach = function (array, fn) { [].forEach.call(array, fn); }; function disableScroll(e){e.preventDefault();} // slide if (typeof TouchSlide == "function") { function focusBn(cell){ TouchSlide({slideCell:cell, titCell:".hd", mainCell:".bd", effect:"leftLoop", autoPlay:true, autoPage:true, delayTime: 500, interTime:5000}); } focusBn("#focusbn01"); // TouchSlide({slideCell:"#focusband", mainCell:".bd ul", effect:"left", autoPlay:true, pnLoop: false, delayTime: 500, interTime: 8000}); // (function(){ var honorfocus = document.getElementById("honorfocus"); if (honorfocus) { TouchSlide({slideCell:"#honorfocus", mainCell:".bd ul", titCell:".hd", effect:"leftLoop", autoPlay:true, autoPage:true, delayTime: 500, interTime: 8000, startFun:function(i,c){ var li = honorfocus.querySelectorAll(".bd li"); [].forEach.call(li,function (eachli){ eachli.classList.remove("active"); }) li[i+1].classList.add("active"); } }); var honorfocusUl = honorfocus.querySelector("ul"), honorfocusSecond = honorfocusUl.querySelectorAll("li")[2].cloneNode(true); honorfocusUl.appendChild(honorfocusSecond); }; })(); // function asidefocus(cell,aside,page,play){ TouchSlide({slideCell:cell, mainCell:".bd", titCell:".hd", effect:"leftLoop", delayTime: 500, interTime:5000, autoPage:true, defaultIndex : page || 0, autoPlay: play || false, startFun: function(i){ var asidelm = document.getElementById(aside); if (asidelm) { var activeChild = asidelm.children[i]; activeChild.classList.add("active"); //console.log('removeSiblingClass_active'); removeSiblingClass(activeChild,"active"); }; } }); } asidefocus("#newsfocus","newsfocus-aside",0,"autoPlay"); asidefocus("#focuspicdecs","focuspicdecs-aside",0,"autoPlay"); function TabSlide(cell, cellbd, page, auto){ TouchSlide({ slideCell: cell, defaultIndex : page || 0, effect:"leftLoop", autoPlay: auto, interTime: 10000, endFun: function(i){ //楂樺害鑷€傚簲 var bd = document.getElementById(cellbd); bd.parentNode.style.height = bd.children[i+1].children[0].offsetHeight+"px"; if(i>0)bd.parentNode.style.transition="200ms";//娣诲姞鍔ㄧ敾鏁堟灉 } }); } TabSlide("#tabBox01", "tabBox01-bd",0,false); }; // end slide document.addEventListener("DOMContentLoaded", function(){ var $$html = document.querySelector("html"); var $$body = document.querySelector("body"); // map //ForEach($$(".contactmap_siteitem"), function (el){ // el.addEventListener("click", function(){ // var _ths = this; // //console.log('removeSiblingClass_selected'); // removeSiblingClass(_ths,"selected"); // if (contactmap) { // var pointX = _ths.dataset["mappointx"], // pointY = _ths.dataset["mappointy"]; // if (pointX && pointY) { // contactmap.panTo(new BMap.Point(pointX,pointY)); // }; // }; // }); //}); // end map ForEach($$(".distancenav"), function (el){ var _box = el, _list = _box.querySelector(".list"), onli = _list.querySelector(".on"); if (onli) { var fixmargin = parseInt(getComputedStyle(onli).marginLeft) || 0, toDistance = onli.offsetLeft + onli.clientWidth + fixmargin - _box.clientWidth; if (toDistance>0) { _list.scrollLeft = toDistance; }; }; }) // fallswitch fallswitch(".draweritem .hasfall",".draweritem","open"); // end fallswitch // anchorbar anchorbar("aboutcompany",".anchorsection"); // end anchorbar // select ForEach($$(".selint_select"),function (el){ el.addEventListener("change", function(){ var selint = closest(this,".selint"), selintLabel = selint.querySelector(".selint_label"); if (selintLabel.nodeName == "INPUT") { selintLabel.value = this.options[this.options.selectedIndex].text; }else{ selintLabel.textContent = this.options[this.options.selectedIndex].text; } }); }); // end select }); // sidemenu function callmenu(id,cls){ var $$html = document.querySelector("html"); var obj = document.getElementById(id); if($$html.classList.contains(cls)){ $$html.classList.remove(cls); $$html.off("touchmove", disableScroll); }else{ $$html.classList.add(cls); $$html.on("touchmove", disableScroll); obj ? obj.on("touchmove", function(e){e.stopPropagation()}) : 0; } } function hidemenu(cls){ var $$html = document.querySelector("html"); $$html.classList.remove(cls); $$html.off("touchmove", disableScroll); } // end sidemenu // fallswitch function fallswitch(dt,dl,cls){ ForEach($$(dt), function (el){ el.addEventListener("click", function(){ closest(el,dl).classList.toggle(cls); }); }); } // end fallswitch // anchorbar function anchorbar(wrap,bditem){ var navbarWrap = document.getElementById(wrap); if (navbarWrap) {var navbar = navbarWrap.querySelector(".navHd");}; if(navbarWrap && navbar){ var $$html = document.querySelector("html"); var navbarWrapTop = getOffset(navbarWrap).top, navbarWrapHeight = navbarWrap.clientHeight, navbox = navbar.querySelector(".clnavtab"), navList = navbar.querySelector(".list"), navlink = navbar.querySelectorAll("li"), navWidth = navList.parentNode.clientWidth, navHeight = navbar.clientHeight, navListWidth = navList.clientWidth, navTranMaxLeft = navListWidth - navWidth, anchorbox = navbarWrap.querySelectorAll(bditem), transZRegex = /\.*translateX\((.*)px\)/i, fixedTopheight = navHeight || 40; setStyle(navList,{ transitionDuration: "600ms", webkitTransitionDuration: "600ms", transitionTimingFunction: "cubic-bezier(0.1, 0.57, 1)", Transform: "translateX(0px)", webkitTransform: "translateX(0px)" }); function goanchor(offtop){ if (offtop>navbarWrapTop) { !navbar.classList.contains("navbar_fixed") ? navbar.classList.add("navbar_fixed") : 0; if (offtop>navbarWrapTop+navbarWrapHeight-fixedTopheight) { navbar.classList.remove("navbar_fixed"); }; }else{ navbar.classList.remove("navbar_fixed"); } ForEach(anchorbox, function (bdel){ var anchor = bdel.dataset["anchor"], anchorH = bdel.clientHeight, anchorTop = getOffset(bdel).top - fixedTopheight; anchorMaxTop = anchorTop + anchorH; if (offtop>anchorTop && offtop=0 && navTranLeft>=navTranMaxLeft){ setStyle(navList,{ transitionDuration: "600ms", webkitTransitionDuration: "600ms", Transform: "translateX(-" + navTranMaxLeft + "px)", webkitTransform: "translateX(-" + navTranMaxLeft + "px)" }); }else if(navTranLeft>=0 && navTranLeft navTranMaxLeft) { init.tx = navTranMaxLeft; setStyle(_ths,{ Transform: "translateX(-"+navTranMaxLeft+"px)", webkitTransform: "translateX(-"+navTranMaxLeft+"px)" }); }else{ init.tx = endX; setStyle(_ths,{ Transform: "translateX(-"+endX+"px)", webkitTransform: "translateX(-"+endX+"px)" }); } }); } categoryScorll(navList); ForEach(navlink, function (hdel){ hdel.addEventListener("click", function (e){ e.preventDefault(); //console.log('removeSiblingClass_on_2'); removeSiblingClass(hdel,"on"); var anchor = hdel.dataset["srv"]; if (anchor) { ForEach(anchorbox, function (bdel){ if (bdel.dataset["anchor"] == anchor) { var anchorTop = getOffset(bdel).top - fixedTopheight + 1; document.documentElement.scrollTop = anchorTop; document.body.scrollTop = anchorTop; }; }); }; }); }); // end hd }; } // end anchorbar // 璁剧疆css function setStyle(obj,json){ for(var i in json) { obj.style[i]=json[i]; } } // end 璁剧疆css // getOffset function getOffset (el) { const box = el.getBoundingClientRect(); return { top: box.top + window.pageYOffset - document.documentElement.clientTop, left: box.left + window.pageXOffset - document.documentElement.clientLeft } } // end getOffset function removeSiblingClass (obj, cls) { //console.log('obj:'); //console.log(obj); Array.prototype.filter.call(obj.parentNode.children, function (child){ //console.log('child:'); //console.log(child); if (child !== obj) { child.classList.remove(cls); }; obj.classList.add(cls); }); } function closest(el, selector) { const matchesSelector = el.matches || el.webkitMatchesSelector || el.mozMatchesSelector || el.msMatchesSelector; while (el) { if (matchesSelector.call(el, selector)) { return el; } else { el = el.parentElement; } } return null; }