2017-04-04 1 views
1

다음 코드를 사용하여 링크 간 원활한 이동이 가능하며 완벽하게 작동합니다.모바일에서 다른 스크롤 오프셋

현재 오프셋은 93px이지만 작은 장치에서는 제거하지 않을 경우이 값을 작게하고 싶습니다. 더 작은 해상도의 오프셋 값을 변경할 수 있는지 궁금합니다. 누구든지 도와 줄 수 있습니까?

var jump=function(e) 
    { 
     if (e){ 
      e.preventDefault(); 
      var target = $(this).attr("href"); 
     }else{ 
      var target = location.hash; 
     } 

     $('html,body').animate(
     { 
      scrollTop: $(target).offset().top-93 
     },2000,function() 
     { 
      location.hash = target; 
     }); 

    } 

    $('html, body').hide(); 

    $(document).ready(function() 
    { 
     $('a[href^=#]').bind("click", jump); 

     if (location.hash){ 
      setTimeout(function(){ 
       $('html, body').scrollTop(0).show(); 
       jump(); 
      }, 0); 
     }else{ 
      $('html, body').show(); 
     } 
    }); 

답변

2

당신은 현재 창 높이를 얻을 작은 장치를 탐지 JQuery와 $(window).height() 방법을 사용할 수 있습니다. 이 값에 따라 오프셋을 다르게 표시 할 수 있습니다.

여기에 더 많은 정보 : https://api.jquery.com/height/

관련 문제