2016-08-02 3 views
0

스크롤에 따라 위치를 변경하고 싶습니다. 그리고 그림이 천 단어를 구사하기 때문에, 여기에 내가 원하는 무엇 : https://jsfiddle.net/njz87Lth/1/스크롤에 따라 위치 변경

HTML :

<h1> MY TEXT. orem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. </h1> 
<div class="one"> </div> 
<div class="two"> </div> 

CSS :

body { 
    text-align:center; 
} 

h1 { 
    left: 0; 
    line-height:2; 
    right:0; 
    width:600px; 
    margin-left: auto; 
    margin-right: auto; 
    position:fixed; 
} 

.one, .two { 
    width:600px; 
    position: absolute; 
    left: 0; 
    right:0; 
    margin-left: auto; 
    margin-right: auto; 
} 

.one { 
    top:100px; 
    height:300px; 
    background:grey; 
} 

.two { 
    height:800px; 
    background:pink; 
    margin-top:30px; 
    top:400px; 
} 
여기

enter image description here

을 그리고 내 코드입니다

답변

0

jQuery를 사용해보십시오.

$(window).scroll(function() { 
    $(".one").offset({ left: left, top: top}); 

}); 

offset 값을 사용자의 필요에 따라 지정하십시오.