diff --git a/src/components/horizontalMenu.ts b/src/components/horizontalMenu.ts index 7ea875a6..6cb97dd5 100644 --- a/src/components/horizontalMenu.ts +++ b/src/components/horizontalMenu.ts @@ -42,7 +42,7 @@ function slideTabs(tabContent: HTMLElement, prevTabContent: HTMLElement, toRight tabContent.style.transform = ''; } -export function horizontalMenu(tabs: HTMLElement, content: HTMLElement, onClick?: (id: number, tabContent: HTMLDivElement) => void, onTransitionEnd?: () => void, transitionTime = 300) { +export function horizontalMenu(tabs: HTMLElement, content: HTMLElement, onClick?: (id: number, tabContent: HTMLDivElement) => void, onTransitionEnd?: () => void, transitionTime = 250) { const hideTimeouts: {[id: number]: number} = {}; let prevTabContent: HTMLElement = null; let prevId = -1; @@ -99,13 +99,7 @@ export function horizontalMenu(tabs: HTMLElement, content: HTMLElement, onClick? }; if(tabs) { - let activeStripe: HTMLSpanElement; - if(!tabs.classList.contains('no-stripe')) { - activeStripe = document.createElement('span'); - activeStripe.classList.add('menu-horizontal__stripe'); - - tabs.append(activeStripe); - } + const useStripe = !tabs.classList.contains('no-stripe'); const tagName = 'LI';//tabs.firstElementChild.tagName; tabs.addEventListener('click', function(e) { @@ -139,16 +133,28 @@ export function horizontalMenu(tabs: HTMLElement, content: HTMLElement, onClick? const prev = tabs.querySelector(tagName.toLowerCase() + '.active') as HTMLElement; prev && prev.classList.remove('active'); - if(activeStripe) { - const tabsRect = tabs.getBoundingClientRect(); - const targetRect = target.getBoundingClientRect(); - const width = 50; - activeStripe.style.cssText = `width: ${width}px; transform: translateX(${targetRect.left - tabsRect.left + ((targetRect.width - width) / 2)}px);`; - /* const textRect = target.firstElementChild.getBoundingClientRect(); - activeStripe.style.cssText = `width: ${textRect.width + (2 * 2)}px; transform: translateX(${textRect.left - tabsRect.left}px);`; */ - //activeStripe.style.transform = `scaleX(${textRect.width}) translateX(${(textRect.left - tabsRect.left) / textRect.width + 0.5}px)`; - //console.log('tabs click:', tabsRect, textRect); + // stripe from ZINCHUK + if(useStripe && prevId != -1) { + const indicator = target.querySelector('i')!; + const currentIndicator = target.parentElement.children[prevId].querySelector('i')!; + + currentIndicator.classList.remove('animate'); + indicator.classList.remove('animate'); + + // We move and resize our indicator so it repeats the position and size of the previous one. + const shiftLeft = currentIndicator.parentElement.parentElement.offsetLeft - indicator.parentElement.parentElement.offsetLeft; + const scaleFactor = currentIndicator.clientWidth / indicator.clientWidth; + indicator.style.transform = `translate3d(${shiftLeft}px, 0, 0) scale3d(${scaleFactor}, 1, 1)`; + + console.log(`translate3d(${shiftLeft}px, 0, 0) scale3d(${scaleFactor}, 1, 1)`); + + requestAnimationFrame(() => { + // Now we remove the transform to let it animate to its own position and size. + indicator.classList.add('animate'); + indicator.style.transform = 'none'; + }); } + // stripe END target.classList.add('active'); selectTab(id); diff --git a/src/components/scrollable_new.ts b/src/components/scrollable_new.ts index 7414b5df..3fc0d328 100644 --- a/src/components/scrollable_new.ts +++ b/src/components/scrollable_new.ts @@ -1,6 +1,6 @@ import { logger, LogLevels } from "../lib/logger"; import smoothscroll from '../vendor/smoothscroll'; -import { touchSupport, isSafari } from "../lib/config"; +import { touchSupport, isSafari, mediaSizes } from "../lib/config"; //import { isInDOM } from "../lib/utils"; (window as any).__forceSmoothScrollPolyfill__ = true; smoothscroll.polyfill(); @@ -207,7 +207,7 @@ export default class Scrollable { const binded = this.onScroll.bind(this); window.addEventListener('resize', () => { - this.overflowContainer = window.innerWidth <= 720 && false ? document.documentElement : this.container; + this.overflowContainer = mediaSizes.isMobile && false ? document.documentElement : this.container; this.onScroll(); }); this.container.addEventListener('scroll', binded, {passive: true, capture: true}); @@ -221,7 +221,7 @@ export default class Scrollable { } //this.onScroll(); - this.overflowContainer = window.innerWidth <= 720 && false ? document.documentElement : this.container; + this.overflowContainer = mediaSizes.isMobile && false ? document.documentElement : this.container; /* scrollables.set(this.container, this); scrollsIntersector.observe(this.container); */ @@ -342,8 +342,13 @@ export default class Scrollable { public checkForTriggers(container: HTMLElement) { if(this.scrollLocked || (!this.onScrolledTop && !this.onScrolledBottom)) return; - const scrollTop = container.scrollTop; - const maxScrollTop = container.scrollHeight - container.clientHeight; + const scrollHeight = container.scrollHeight; + if(!scrollHeight) { // незачем вызывать триггеры если блок пустой или не виден + return; + } + + const {clientHeight, scrollTop} = container; + const maxScrollTop = scrollHeight - clientHeight; //this.log('checkForTriggers:', scrollTop, maxScrollTop); diff --git a/src/components/slider.ts b/src/components/slider.ts index 3399aeff..b4de565a 100644 --- a/src/components/slider.ts +++ b/src/components/slider.ts @@ -7,7 +7,7 @@ export interface SliderTab { onCloseAfterTimeout?: () => void } -const TRANSITIONTIME = 420; +const TRANSITIONTIME = 250; export default class SidebarSlider { protected _selectTab: (id: number) => void; diff --git a/src/index.hbs b/src/index.hbs index 91fe23c7..3fe0b94c 100644 --- a/src/index.hbs +++ b/src/index.hbs @@ -212,9 +212,9 @@