풀페이지 스크롤 예시 > 기타팁(프로그램)

본문 바로가기
사이트 내 전체검색

오늘 본 상품 0

없음


기타팁(프로그램)

풀페이지 스크롤 예시

페이지 정보

profile_image
작성자 유토하우스
댓글 0건 조회 1,671회 작성일 23-04-28 09:45

본문

안녕하십니까?

유토하우스 유토맨입니다


CodePen Home Sticky Slider Nav v2 (Responsive) 

https://codepen.io/ettrics/details/Wpbxgw 


1. html

<header class="et-header"> 

  <div class="et-header__left">

    <a href="" class="et-header__logo">Ettrics</a>

  </div>

</header>


<section class="et-hero-tabs">

  <h1>STICKY SLIDER NAV V2</h1>

  <h3>Sliding content with sticky tab nav</h3>

  <div class="et-hero-tabs-container">

    <a class="et-hero-tab" href="#tab-es6">ES6</a>

    <a class="et-hero-tab" href="#tab-flexbox">Flexbox</a>

    <a class="et-hero-tab" href="#tab-react">React</a>

    <a class="et-hero-tab" href="#tab-angular">Angular</a>

    <a class="et-hero-tab" href="#tab-other">Other</a>

    <span class="et-hero-tab-slider"></span>

  </div>

</section>


<main class="et-main">

  <section class="et-slide" id="tab-es6">

    <h1>ES6</h1>

    <h3>something about es6</h3>

  </section>

  <section class="et-slide" id="tab-flexbox">

    <h1>Flexbox</h1>

    <h3>something about flexbox</h3>

  </section>

  <section class="et-slide" id="tab-react">

    <h1>React</h1>

    <h3>something about react</h3>

  </section>

  <section class="et-slide" id="tab-angular">

    <h1>Angular</h1>

    <h3>something about angular</h3>

  </section>

  <section class="et-slide" id="tab-other">

    <h1>Other</h1>

    <h3>something about other</h3>

  </section>

</main>


2. css

//

// Body 

//


body {

  font-family: "Century Gothic", "Lato", sans-serif;

}


a {

  text-decoration: none;

}


//

// Header 

//


.et-header {

  display: flex;

  flex-direction: row;

  justify-content: space-between;

  align-items: center;

  position: fixed;

  top: 0;

  left: 0;

  right: 0;

  padding: 0 2em;

  height: 75px;

  z-index: 2;

  transition: all 0.3s cubic-bezier(0.19, 1, 0.22, 1);

  &--scrolled {

    background: #fff;

    box-shadow: 0 0 20px rgba(0, 0, 0, 0.3);

  }

  &--move-up {

    transform: translateY(-75px);

    transition: all 0.3s cubic-bezier(0.19, 1, 0.22, 1);

  }

  &__logo {

    color: #000;

  }

  &__link {

    margin-left: 1em;

    color: #000;

  }

}


//

// Hero 

//


.et-hero-tabs,

.et-slide {

    display: flex;

    flex-direction: column;

    justify-content: center;

    align-items: center;

    height: 100vh;

    position: relative;

    background: #eee;

    text-align: center;

    padding: 0 2em;

    h1 {

        font-size: 2rem;

        margin: 0;

        letter-spacing: 1rem;

    }

    h3 {

        font-size: 1rem;

        letter-spacing: 0.3rem;

        opacity: 0.6;

    }

}


.et-hero-tabs-container {

    display: flex;

    flex-direction: row;

    position: absolute;

    bottom: 0;

    width: 100%;

    height: 75px;

    box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);

    background: #fff;

    z-index: 1;

    transition: all 0.3s cubic-bezier(0.19, 1, 0.22, 1);

    &--top-first {

      position: fixed;

      top: 75px;

      transition: all 0.3s cubic-bezier(0.19, 1, 0.22, 1);

    }

    &--top-second {

      position: fixed;

      top: 0;

    }

}


.et-hero-tab {

    display: flex;

    justify-content: center;

    align-items: center;

    flex: 1;

    color: #000;

    letter-spacing: 0.1rem;

    transition: all 0.5s ease;

    font-size: 0.8rem;

    &:hover {

      color:white;

      background: rgba(102,177,241,0.8);

      transition: all 0.5s ease;

    }

}


.et-hero-tab-slider {

    position: absolute;

    bottom: 0;

    width: 0;

    height: 6px;

    background: #66B1F1;

    transition: left 0.3s ease;

}


@media (min-width: 800px) {

  .et-hero-tabs,

  .et-slide {

    h1 {

        font-size: 3rem;

    }

    h3 {

        font-size: 1rem;

    }

  }

  .et-hero-tab {

    font-size: 1rem;

  }

}


3. js

HTML SCSS JSResult Skip Results Iframe

class StickyNavigation {

  

  constructor() {

    this.currentId = null;

    this.currentTab = null;

    this.tabContainerHeight = 70;

    this.lastScroll = 0;

    let self = this;

    $('.et-hero-tab').click(function() { 

      self.onTabClick(event, $(this)); 

    });

    $(window).scroll(() => { this.onScroll(); });

    $(window).resize(() => { this.onResize(); });

  }

  

  onTabClick(event, element) {

    event.preventDefault();

    let scrollTop = $(element.attr('href')).offset().top - this.tabContainerHeight + 1;

    $('html, body').animate({ scrollTop: scrollTop }, 600);

  }

  

  onScroll() {

    this.checkHeaderPosition();

    this.findCurrentTabSelector();

    this.lastScroll = $(window).scrollTop();

  }

  

  onResize() {

    if(this.currentId) {

      this.setSliderCss();

    }

  }

  

  checkHeaderPosition() {

    const headerHeight = 75;

    if($(window).scrollTop() > headerHeight) {

      $('.et-header').addClass('et-header--scrolled');

    } else {

      $('.et-header').removeClass('et-header--scrolled');

    }

    let offset = ($('.et-hero-tabs').offset().top + $('.et-hero-tabs').height() - this.tabContainerHeight) - headerHeight;

    if($(window).scrollTop() > this.lastScroll && $(window).scrollTop() > offset) {

      $('.et-header').addClass('et-header--move-up');

      $('.et-hero-tabs-container').removeClass('et-hero-tabs-container--top-first');

      $('.et-hero-tabs-container').addClass('et-hero-tabs-container--top-second');

    } 

    else if($(window).scrollTop() < this.lastScroll && $(window).scrollTop() > offset) {

      $('.et-header').removeClass('et-header--move-up');

      $('.et-hero-tabs-container').removeClass('et-hero-tabs-container--top-second');

      $('.et-hero-tabs-container').addClass('et-hero-tabs-container--top-first');

    }

    else {

      $('.et-header').removeClass('et-header--move-up');

      $('.et-hero-tabs-container').removeClass('et-hero-tabs-container--top-first');

      $('.et-hero-tabs-container').removeClass('et-hero-tabs-container--top-second');

    }

  }

  

  findCurrentTabSelector(element) {

    let newCurrentId;

    let newCurrentTab;

    let self = this;

    $('.et-hero-tab').each(function() {

      let id = $(this).attr('href');

      let offsetTop = $(id).offset().top - self.tabContainerHeight;

      let offsetBottom = $(id).offset().top + $(id).height() - self.tabContainerHeight;

      if($(window).scrollTop() > offsetTop && $(window).scrollTop() < offsetBottom) {

        newCurrentId = id;

        newCurrentTab = $(this);

      }

    });

    if(this.currentId != newCurrentId || this.currentId === null) {

      this.currentId = newCurrentId;

      this.currentTab = newCurrentTab;

      this.setSliderCss();

    }

  }

  

  setSliderCss() {

    let width = 0;

    let left = 0;

    if(this.currentTab) {

      width = this.currentTab.css('width');

      left = this.currentTab.offset().left;

    }

    $('.et-hero-tab-slider').css('width', width);

    $('.et-hero-tab-slider').css('left', left);

  }

  

}


new StickyNavigation();



9d74ffa14bdc51781b61001f9612bf8b_1682643549_8299.png
 


추천0

댓글목록

등록된 댓글이 없습니다.


고객센터

카톡문의(ID) : jbm5894 평일 (10:00~17::00) 점심시간 (12:00~13::00) 토,일,공휴일 휴무

입금계좌안내

카카오은행 3333-27-9421813 정병묵

아름다운 공간만들기 | 웹제작 유토하우스 주소 경기 용인시 수지구 죽전동 172-1 E-MAIL. utohouse@gmail.com

개인정보보호책임자 정병묵

네이버블로그인스타그램네이버카페유튜브페이스북트위터카카오
아름다운 공간만들기 | 웹제작 Copyright © 2001-2013 utohouse.co.kr. All Rights Reserved.