/** * 鍙戝睍鍘嗙▼ */ // PC绔 gsap.registerPlugin(ScrollToPlugin); gsap.registerPlugin(ScrollTrigger); setTimeout(initScroll, 1000); overflowHover(); function initScroll() { var scrollDistance = function () { return $('.history1 .stages').get(0).scrollWidth - $('.history1 .stages').width() + rem(1); } var scrollTween = gsap.to($('.history1 .stages .stage_item'), { x: function () { return -scrollDistance(); }, ease: "none", scrollTrigger: { trigger: $('.history1'), pin: true, scrub: 0.1, invalidateOnRefresh: true, start: function () { return 'top-=' + rem(0.8) + 'px top'; }, end: function () { return "+=" + scrollDistance(); } } }); $('.history1 .stages .stage_item').each(function () { var $stage = $(this); var $indi = $('.history1 .indicators .indi_item').eq($stage.index()); var stageLength = $('.history1 .stages .stage_item').length; gsap.fromTo($indi.find('.progress'), { width: 0 }, { width: '100%', ease: "none", scrollTrigger: { trigger: $stage, containerAnimation: scrollTween, start: function() { var pos = "left left"; if($stage.index() == stageLength - 1) { pos = "left center"; } return pos; }, end: function() { var pos = "right left"; if($stage.index() == stageLength - 2) { pos = "right center"; } else if($stage.index() == stageLength - 1) { pos = "right right"; } return pos; }, scrub: 0.1, onEnter: function () { $indi.addClass('cur').siblings().removeClass('cur'); }, onEnterBack: function () { $indi.addClass('cur').siblings().removeClass('cur'); } } }); gsap.to($stage.find('.infor'), { x: function () { return $stage.width() }, ease: 'none', scrollTrigger: { trigger: $stage, containerAnimation: scrollTween, start: 'left left', end: 'right left', scrub: true, invalidateOnRefresh: true } }); gsap.to($stage.find('.infor'), { duration: 0.3, autoAlpha: 0, ease: 'none', scrollTrigger: { trigger: $stage, containerAnimation: scrollTween, start: 'left+=30% left', toggleActions: 'play none none reverse' } }); }); $('.history1 .indicators .indi_item').eq(0).addClass('cur'); $('.history1 .indi_item').on('click', function () { enterStage($(this).index()); }); } function enterStage(index) { var offsetIdx = Math.abs($('.history1 .indicators .indi_item.cur').index() - index); var duration = (offsetIdx + 1) * 0.8; function calcDist(idx) { var dist = 0; // if (idx == ($('.history1 .stages .stage_item').length - 1)) { // dist -= $('.history1 .stages').width() / 2; // } var prev = $('.history1 .stages .stage_item').eq(idx).prev(); if (prev.length > 0) { dist += prev.width(); return dist + calcDist(idx - 1); } else { return dist; } } gsap.to(window, { duration: duration, scrollTo: function () { return $('.history').offset().top + rem(0.2) + calcDist(index) }, ease: "power2" }); } /*function overflowHover() { $('.history1 .stage_item .content .year_item .intro_box').each(function () { if (this.offsetHeight < this.scrollHeight) { $(this).closest('.year_item').on('mouseenter', function () { $(this).addClass('on'); }).on('mouseleave', function () { $(this).removeClass('on'); }); } }); }*/ function rem(count) { var unit = $('html').css('font-size'); if (typeof count !== 'undefined' && count > 0) { return (parseInt(unit) * count); } else { return parseInt(unit); } }