Web
Html 분류

스크롤 이벤트 감지 + jquery + css

작성자 정보

  • webveloper 작성
  • 작성일

컨텐츠 정보

본문

1. css



 .caritem{display:flex;align-items:end;flex-direction:column;background:#002DAC;padding:30px 0;padding-right:80px;margin:15px 0;max-width:500px;color:#fff;font-size:24px;border-radius:30px 0 0 30px;transition:all .5s}

.caritem.del{text-decoration:line-through;transform:rotate(-10deg);color:#220663}

.caritem.del:nth-child(2){transform:rotate(3deg)}

.caritem.del:nth-child(3){transform:rotate(-8deg)}

.caritem.del:nth-child(4){transform:rotate(3deg)}

.caritem span:nth-child(2){font-size:40px;font-weight:700}

 

2. html



<div class="caritem">

  <span>그랜져 3.5 가솔린 프리미엄</span>

  <span>3,990만원</span>

</div>




<div class="caritem">

  <span>그랜져 3.5 가솔린 프리미엄 등록세</span>

  <span>1,995,000원</span>

</div>




<div class="caritem">

  <span>그랜져 3.5 가솔린 프리미엄 취득세</span>

  <span>798,000원</span>

</div>




<div class="caritem">

  <span>그랜져 3.5 가솔린 프리미엄 보험료</span>

  <span>1,150,000원</span>

</div>

 

3. js + jquery



$(document).ready(function() {

  const $counters = $(".caritem");




  const exposurePercentage = 100;

  const loop = true;




  $(window).on('scroll',

  function() {

    $counters.each(function() {

      const $el = $(this);




      const rect = $el[0].getBoundingClientRect();

      const winHeight = window.innerHeight;

      const contentHeight = rect.bottom - rect.top;




      if (rect.top <= winHeight - (contentHeight * exposurePercentage / 100) && rect.bottom >= (contentHeight * exposurePercentage / 100)) {

        $el.addClass('del');

      }




      if (loop && (rect.bottom <= 0 || rect.top >= window.innerHeight)) {

        $el.removeClass('del');

      }

    });

  }).scroll();

});

관련자료

댓글 0
등록된 댓글이 없습니다.
전체 40 / 1 페이지
RSS
  • 웹개발에 자주 쓰는 자바스크립트 라이브러리들 - 슬라이드/갤러리 (Carousel)
    등록자 tjslli
    등록일 05.08 조회 1707

    Html 슬라이드/갤러리 (Carousel) 01. 가장 유명한 Slick - https://kenwheeler.github.io/slick/ 설치 &l…

  • [CSS]css 가상 선택자 정리 및 비교 (nth-child, nth-of-type)
    등록자 CSS러버
    등록일 05.08 조회 1620

    Html :nth-child(N)= 부모안에 모든 요소 중 N번째 요소 A:nth-of-type(N)= 부모안에 A라는 요소 중 N번째 요소 :first…

  • 스크롤 이벤트 감지 + jquery + css
    등록자 webveloper
    등록일 04.15 조회 1732

    Html 1. css .caritem{display:flex;align-items:end;flex-direction:column;background:#0…

  • slick slider 커스텀으로 꾸미기 + jquery 이벤트 감지 + 커스텀 슬라이드 번호
    등록자 webveloper
    등록일 04.15 조회 1770

    Html 1. import <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.n…

  • 호버(hover) 할 때 jquery 이벤트 감지 방법
    등록자 webveloper
    등록일 04.15 조회 1781

    Html 안녕하세요. html 코딩 시 hover 할때 감지하는 이벤트 스크립트입니다. <style> .con-group { display: …

  • 그누보드 썸네일 이미지 화질 개선 방법
    등록자 PixelProphet
    등록일 01.10 조회 2729

    Php 그누보드에서 이미지를 올릴때, 간혹 이미지 화질이 떨어져 보이는 현상이 있습니다.... 이럴 때 제가 찾아본 방법 중에 가장 쉽게 해결 할 수 …

  • React 유튜브 채널 추천
    등록자 코드워리어
    등록일 01.09 조회 2192

    React React는 웹 개발에서 매우 인기 있는 라이브러리로, 학습을 위해 다양한 자료들이 필요합니다. React를 학습하고 싶은 분들을 위한 유튜버 …

  • PHP 배열의 기초
    등록자 console
    등록일 01.05 조회 2521

    Php 배열(array)이란? PHP에서 배열(array)은 맵(map)으로 이루어진, 순서가 있는 집합을 의미합니다. 맵(map)은한 쌍의 키(key…

  • PHP 기타 제어문
    등록자 console
    등록일 01.05 조회 2553

    Php 루프의 제어 일반적으로 조건식의 검사를 통해 루프로 진입하면,다음 조건식을검사하기 전까지 루프 안에 있는 모든 명령문을 실행합니다. 사용자는 c…

  • PHP 반복문
    등록자 console
    등록일 01.05 조회 2524

    Php 반복문 반복문이란 프로그램 내에서 같은 명령을 일정 횟수만큼 반복하여수행하는명령문입니다. 프로그램이 처리하는 대부분의코드는 반복적인 형태가 많으…

  • PHP 조건문
    등록자 console
    등록일 01.05 조회 2375

    Php PHP 표현식 표현식(expressions)은 PHP에서 가장 중요한 구성요소입니다. 표현식이란 모든 것이 값을 갖는다는 의미이며, PHP에서 …

  • PHP 기타 연산자
    등록자 console
    등록일 01.05 조회 2342

    Php 삼항 연산자(ternaryoperator) 삼항 연산자는 유일하게 피연산자를 세 개나 가지는 조건 연산자입니다. 삼항 연산자의 문법은 다음과 같…

  • PHP 비트 연산자
    등록자 console
    등록일 01.05 조회 2552

    Php 비트 연산자(bitwise operator) 비트 연산자는 논리 연산자와 비슷하지만, 비트(bit) 단위로 논리 연산을 수행합니다. 또한, 비트…

  • PHP 논리 연산자
    등록자 console
    등록일 01.05 조회 2608

    Php 논리 연산자(logical operator) 논리 연산자는 논리식을 판단하여, 참(true)과 거짓(false)을 반환합니다. and, or, …

  • PHP 비교 연산자
    등록자 console
    등록일 01.05 조회 2625

    Php 비교 연산자(comparisonoperator) 비교 연산자는피연산자사이의 상대적인 크기를 판단하여,참(true)과 거짓(false)을 반환합니…