; (function ($, window, document, undefined) { 'use strict'; var GsapAnimate = (function () { var defaults = { mainDomAnime: true, scrollTopAnime: false, slideNavAnime: false, fixHeader: false, navMaxSreen: null,//导航咱开, duration: 0.4,//动画执行 bannerPage:false, delay: 0//动画延迟时间 }, options = {}; return { init: function (opts) { options = $.extend(defaults, opts); // gsap.to(".mbanner .inner", { // scale: 1.15, // rotationX:-20, // scrollTrigger: { // trigger: ".mbanner", //监视区域 // scrub: true,//擦洗 // start: "top top", // end: "bottom top", // } // }) if(options.bannerPage){ document.querySelector("body").classList.add("bannerPage") document.addEventListener('wheel', function (event) { var delta = event.deltaY; //console.log(window.pageYOffset,window.innerHeight) // // 阻止默认行为,防止页面滚动 console.log(window.pageYOffset,delta ) if (window.pageYOffset==0) { $('html, body').animate({ scrollTop: document.querySelector(".body_m").offsetTop }); }else if(window.pageYOffset<=(window.innerHeight+100)&&delta < 0){ $('html, body').animate({ scrollTop: 0 }); } }); } if (options.mainDomAnime) { const dom = gsap.utils.toArray('.gsapdom') //模块动画 dom.forEach((item) => { const position = item.getAttribute("gsap-position") const direction = item.getAttribute("gsap-direction").toUpperCase() || options.direction const delay = item.getAttribute("delay") || options.delay const fix= item.getAttribute("fix") || "100" gsap.from(item, { duration: 0.6, //动画执行时间 delay, //动画延迟时间 opacity: "0", transform: direction=="X"||direction=="Y"?`translate${direction}(${position}px)`:`${direction}(${position})`, scrollTrigger: { trigger: item, //监视区域 //scrub: true,//擦洗 start:`top ${fix}%`, end: direction == "Y" && position > 0 ? `top bottom+=${position * 2}px` : "top bottom", toggleActions: "play none reverse none" //重置 }, onLeave: (self) => { }, onUpdate: (self) => { if (ScrollTrigger.isInViewport(item)) { //element是否在视野内 if (!item.classList.contains("showdiv")) { item.classList.add("showdiv") } } }, }) }) } if (options.scrollTopAnime) { //top按钮 gsap.from(options.scrollTopAnime, { duration: 0.4, //动画执行时间 opacity: "0", y: 200, scrollTrigger: { trigger: ".main1", //监视区域 start: "top center", end: "top bottom", toggleActions: "play none reverse none" //重置 } }) } if (options.slideNavAnime) { //侧导航 gsap.from(options.slideNavAnime, { duration: 0.4, //动画执行时间 opacity: "0", x: 200, scrollTrigger: { trigger: ".main1", //监视区域 start: "top center", end: "top bottom", toggleActions: "play none reverse none"//重置 } }) } if (options.fixHeader) { //滚动导航固定在顶部(放公共样式) const headerEle = document.querySelector(".header") document.addEventListener('scroll', function () { if (window.scrollY >= 500) { headerEle.style.position = 'fixed' headerEle.style.transform = 'translateY(0%)' headerEle.classList.add("fix") } else if (window.scrollY < 500 && window.scrollY >= 250) { headerEle.style.transform = 'translateY(-250%)' } else { headerEle.style.position = 'absolute' headerEle.style.transform = 'translateY(0%)' headerEle.classList.remove("fix") } }) } if (options.navMaxSreen != null) { const c = options.navMaxSreen, a = GsapAnimate //大屏导航,根据属性data-fixnav-num排序(放公共样式) const mobileNavEle = document.querySelectorAll("[data-fixnav-num]") var _menu = [] mobileNavEle.forEach(function (item) { const num = item.getAttribute("data-fixnav-num") _menu[num] = item.cloneNode(true) }) _menu.forEach((el) => { document.querySelector(c.box).appendChild(el) }) document.querySelector(c.control).addEventListener("click", function () { $("body").toggleClass("showNav") if (this.classList.contains("arrow")) { a.fixboxClose(c.box, undefined, c.hideDom) this.classList.remove("arrow") } else { this.classList.add("arrow") a.fixboxAlert(c.box, undefined, c.hideDom) } }) //手机端点击,二级导航下拉(放公共样式) document.querySelectorAll(".menu-switch-arrow").forEach((item) => { item.addEventListener("click", function () { if (item.classList.contains("open")) { gsap.to(item.nextElementSibling, { height: "0", opacity: 0 }) item.classList.remove("open") } else { item.classList.add("open") gsap.fromTo(item.nextElementSibling, { height: "0", opacity: 0 }, { height: "auto", opacity: 1 }) } }) }) } }, fixboxAlert: function (alertEle, duration = 0.5, fixhid = []) { var tl = gsap.timeline(); const alertElement = document.querySelector(alertEle) const isMobile = window.innerWidth > 999 ? false : true //隐藏元素 if (fixhid.length != 0) { fixhid.forEach((item) => { tl.to(item, { duration: 0.2, //动画执行时间 autoAlpha: "0", }, "-=0.3") }) } tl.to(alertElement, { clipPath: `circle(${isMobile ? 2000 : window.innerWidth * 1.1 + 250}px at 100% 50%)`, autoAlpha: 1 }) alertElement.childNodes.forEach((item) => { if (item.nodeType === 1) tl.fromTo(item, { y: 200, opacity: 0 }, { y: 0, opacity: 1, duration }, "-=0.3") }) document.documentElement.style.overflow = 'hidden'; }, fixboxClose: function (closeEle, duration = 0.5, fixhid = []) { var t2 = gsap.timeline(); const closeElement = document.querySelector(closeEle) Array.from(closeElement.childNodes).reverse().forEach((item) => { t2.fromTo(item, { y: 0, opacity: 1 }, { y: 200, opacity: 0 }, "-=0.3") }) t2.to(closeElement, { clipPath: 'circle(35px at 110% 0px)', autoAlpha: 0, duration, }, "-=0.3") //需要显示元素 if (fixhid.length != 0) { fixhid.forEach((item) => { t2.to(item, { duration: 0, //动画执行时间 autoAlpha: "1", }, "<") }) } document.documentElement.style.overflow = 'auto'; } } })(); window.GsapAnimate = GsapAnimate; })(jQuery, window, document);