From f571f637d11da14991358c0112aca7c4580f7d7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cain=C3=A3=20Milech?= Date: Wed, 7 Dec 2022 19:32:03 -0300 Subject: [PATCH] feat: torna o header fixo no scroll --- src/arquivos/js/app/components/FixedHeader.js | 51 ++++++------------ src/arquivos/sass/partials/_header.scss | 54 ++++--------------- src/template-pagina/caina-home.html | 2 +- 3 files changed, 28 insertions(+), 79 deletions(-) diff --git a/src/arquivos/js/app/components/FixedHeader.js b/src/arquivos/js/app/components/FixedHeader.js index 0916421..42ef2a1 100644 --- a/src/arquivos/js/app/components/FixedHeader.js +++ b/src/arquivos/js/app/components/FixedHeader.js @@ -1,45 +1,28 @@ -import { isSmallerThen768 } from "Helpers/MediasMatch"; +import { isSmallerThen991 } from "Helpers/MediasMatch"; export default class FixedHeader { constructor() { - if (!isSmallerThen768) { - this.fixedHeader(); + if (!isSmallerThen991) { + this.selectors(); + this.events(); } } - fixedHeader() { - var lastScroll = 0; - var timer, scrollTop, headerHeight; - var element = $("header.header"); + selectors() { + this.pageHeader = $(".page-header"); + } - $(document).scroll(function (e) { - headerHeight = element.height(); - scrollTop = $(document).scrollTop(); + events() { + $(document).scroll(this.fixHeader.bind(this)); + } - if (scrollTop > 1) { - $("body").css("padding-top", headerHeight); - element.addClass("fixed"); + fixHeader() { + const topScroll = $(document).scrollTop(); - if (timer) { - window.clearTimeout(timer); - } - - timer = window.setTimeout(function () { - if ( - scrollTop > lastScroll && - scrollTop > element.height() + 20 - ) { - element.addClass("fixed-hide"); - } else { - element.removeClass("fixed-hide"); - } - - lastScroll = $(document).scrollTop(); - }, 50); - } else { - element.removeClass("fixed"); - $("body").css("padding-top", 0); - } - }); + if (topScroll > 200) { + this.pageHeader.addClass("is-fixed"); + } else { + this.pageHeader.removeClass("is-fixed"); + } } } diff --git a/src/arquivos/sass/partials/_header.scss b/src/arquivos/sass/partials/_header.scss index 37a8c1a..c2c2bea 100644 --- a/src/arquivos/sass/partials/_header.scss +++ b/src/arquivos/sass/partials/_header.scss @@ -1,5 +1,4 @@ .page-header { - position: relative; padding: 28px 0; background: $black-500; @@ -7,6 +6,16 @@ padding: 18px 0 0; } + @include mq(lg, min) { + /*fixar no topo*/ + position: sticky; + top: 0; + } + + &.is-fixed { + background: rgba($black-500, 0.9); + } + &__wrapper { display: grid; grid-template-columns: 2fr 1fr 2fr; @@ -70,49 +79,6 @@ } } - .minicart { - &__button { - position: relative; - padding: 0; - border: 0; - outline: 0; - background: transparent; - cursor: pointer; - - .portal-totalizers-ref { - .title, - .amount-products, - .amount-items strong, - .amount-kits, - .total-cart { - display: none; - } - } - - .cart-info { - margin: 0; - } - - .amount-items-em { - display: flex; - align-items: center; - justify-content: center; - position: absolute; - top: 4px; - right: -4px; - width: 15px; - height: 15px; - border-radius: 50%; - font-style: normal; - font-weight: 700; - font-size: 9px; - line-height: 11px; - color: $white-500; - background: $blue-500; - } - } - } - &__search-box { margin-top: 18px; border-top: 1px solid $gray-500; diff --git a/src/template-pagina/caina-home.html b/src/template-pagina/caina-home.html index 6cd2a71..8e8aaa8 100644 --- a/src/template-pagina/caina-home.html +++ b/src/template-pagina/caina-home.html @@ -22,7 +22,7 @@ -
+