링크 클릭 시 타 페이지 특정 영역 이동

Sukyeong·2024년 8월 7일
0
  <div class="ns4_tit4 pointer btn_more" onclick='location.href="/pages/sub3/artificial.php#type"'>
       <p><span class="c2">인공수정체</span> 더보기</p>
  </div>
<script defer>
    "use strict";
    window.onload = function () {
            if (window.location.hash === "#type") {
                setTimeout(function() {
                    var element = document.getElementById('type');
                    if (element) {
                        var rect = element.getBoundingClientRect();
                        var top = rect.top + window.pageYOffset; // 요소의 top 위치 계산
                        window.scrollTo({ top: top});
                    }
                }, 100); // 필요시 대기 시간 조정
            }
        };
</script>

0개의 댓글