2014-02-18 1 views
1

이 스크립트는 이후에 수행 한 작업을 수행하므로 고정 폭의 너비가 작동하지 않습니다. "100 % 높이;" jQuery 컨테이너의 끝까지 도달 할 때 컨테이너에 고정하는 방법

http://benoit.pointet.info/stuff/jquery-scrollsnap-plugin/

그래서 필자는 정말 후 div의 어떤 높이가 될 수 있도록, 사업부의 끝에 도달 할 때 스냅 플러그인 무엇 그것은 단지와 함께 작동합니다.

내 페이지의 div는 각각 약 2000 픽셀이므로 사용자가 div의 하단에 도달하면 플러그인에서 볼 수 있듯이 사용자가 div의 하단에 도달하면 다음 섹션 (또는 사용자가 충분히 아래로 스크롤하지 않은 경우 현재 페이지)으로 스냅합니다. .

답변 감사합니다!

답변

0

waypoints 플러그인을 확인합니다.

현재 섹션이 맨 아래에 도달하면 내 데모가 스냅되도록 변경했습니다.

섹션 높이가 커서 사용자가 충분히 스크롤하지 않아도 해당 섹션의 내용을 볼 수 없으면 현재 섹션의 맨 위로 스냅하지 않아야합니다.

바쳐 대한

http://jsfiddle.net/T89LF/4/show

http://jsfiddle.net/T89LF/4/

HTML

<section></section> 
<section></section> 
<section></section> 
<section></section> 
<section></section> 

jQuery를

$('section').waypoint(function(direction) { 
    if(direction == 'down'){ 
     disable_scroll(); 
     //Animate to top of the section 
     $('html, body').stop().animate({ 
      scrollTop: $(this).offset().top 
     },300,"easeInOutQuart", function() { 
      enable_scroll(); 
     }); 
    } 
}, { offset: '100%' }); 

function preventDefault(e) { 
    e = e || window.event; 
    if (e.preventDefault) 
     e.preventDefault(); 
    e.returnValue = false; 
} 

function wheel(e) { 
    preventDefault(e); 
} 

function disable_scroll() { 
    if (window.addEventListener) { 
     window.addEventListener('DOMMouseScroll', wheel, false); 
    } 
    window.onmousewheel = document.onmousewheel = wheel; 
} 

function enable_scroll() { 
    if (window.removeEventListener) { 
     window.removeEventListener('DOMMouseScroll', wheel, false); 
    } 
    window.onmousewheel = document.onmousewheel = null; 
} 
+0

안녕, 정말 고마워요 데모 대답 할 시간. 이 솔루션의 문제점은 백업 화면을 스크롤 할 때 스냅해야하며이 화면과 같이 가장 가까운 부분과 가장 가까운 부분에 따라 상단 또는 하단의 두 섹션 사이에있을 때 스냅됩니다 (http : // d). .pr/i/uA3F - 스냅하는 부분까지 아래로 스크롤 한 다음 다시 스크롤하십시오. 다시 튀어 나와야합니다. 감사! – user3067058

+0

나는 먼저 그런 것을했는데, http://jsfiddle.net/T89LF/1/show/ 그러나 이것은 당신이 내용을 읽었을 때 짜증나게 할 부분의 어느 지점에서나 짤 것이다. 그래서 나는 이것을 다시 볼 필요가있다. – hyperdrive

+0

안녕하세요. 정말 고맙습니다! 그게 바로 제가 찾고 있던 것입니다! :) 감사!! – user3067058

관련 문제