$(document).ready(function(){
var aligned = false; // A flag to tell us when the images are aligned
$(window).scroll(function(){
if($(this).scrollTop() == 192) { // when the window scroll to the alignment point...
aligned = true; // the images are aligned
}
if (aligned) { // if they're aligned...
$(".image-2").css("top", 8 + $(this).scrollTop()) // match .image-2's top css property
} // to the window's scrollTop value, +
// 8px for the body's margin.
})
})
Here's a JSFiddle with what I think you want.
이미지가 줄 때 우리를 알려주는 부울 단순히있다. 이미지 -2의 CSS 속성 'top'은 윈도우의 scrollTop 값과 일치합니다.
부울 변수는 이미지가 줄 지어있을 때 알려주기 위해 현재 하드 코딩되어 있습니다 (줄을 맞췄을 때이 윈도우의 scrollTop 값을 보았습니다.이 경우 192). 이것은 이미지의 위치 나 크기의 변화를 설명하지 않기 때문에 큰 접근법은 아니지만이 방법을 사용하면 충분합니다.
편집
https://jsfiddle.net/eLdo0s3w/5/
여기서 동일한 결과를 달성하는 다른 방법이다. 오랫동안 두 번째 이미지 position: fixed
을 가지고있는 것이 좋습니다. 그러면 더 효율적이어야하며, 첫 번째 방법으로 OP가 발생했다고 점프하는 것을 피할 수 있습니다.
image-2의 top
CSS 속성을 대상으로하고 image-2가 필요한 지점에 도달 할 때까지 window.scrollTop 값과 일치시킵니다.
이 코드는 다시는 재사용 할 수 없지만 일회성 상황에서는 정상적으로 작동합니다. 누구든지 개선하고 싶다면 그렇게하십시오!
지금까지 작성한 코드를 공유 할 수 있습니까? – DinoMyte
코드 도움말을 찾는 질문은 ** 자체적으로 ** [Stack Snippet] (https://stackoverflow.blog/2014/09/introducing-runnable-https : javascript-css-and-html-code-snippets /) 또는 [JSFiddle] (https://jsfiddle.net/). [Minimal, Complete, Verifiable example]을 만드는 방법을 참조하십시오 (http://stackoverflow.com/help/mcve). – paolobasso
다음과 같이 시도해보십시오. https://jsfiddle.net/xfp34c0o/ – DinoMyte