나는 이것으로별로 좋지 않아서 이것을 이해할 수 없습니다. 3 개의 버튼과 3 개의 숨겨진 div가 있습니다. 버튼을 클릭하면 숨겨진 내용이 표시됩니다. 내용의 시작 부분이 페이지 상단에 있도록 페이지를 아래로 스크롤 할 수 있습니까?숨겨진 div가 표시 될 때 콘텐츠로 스크롤
<script type="text/javascript">
function showDiv(num) {
document.getElementById('div1').style.visibility='hidden';
document.getElementById('div1').style.height='0px';
document.getElementById('div1').style.overflow='hidden';
document.getElementById('div2').style.visibility='hidden';
document.getElementById('div2').style.height='0px';
document.getElementById('div2').style.overflow='hidden';
document.getElementById('div3').style.visibility='hidden';
document.getElementById('div3').style.height='0px';
document.getElementById('div3').style.overflow='hidden';
document.getElementById('div'+num).style.visibility='visible';
document.getElementById('div'+num).style.height='10px';
document.getElementById('div'+num).style.overflow='visible';
}
</script>
내 CSS는 :
#div1, #div2, #div3 {
visibility: hidden;
height:0px;
overflow:hidden
}
.button {
background-color: green;
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 22px;
cursor: pointer;
font-family: Arial;
}
내 버튼 :
<input type="button" class="button" name="Showdiv1" value="Show Div 1" onclick="showDiv('1')" />
<input type="button" class="button" name="Showdiv2" value="Show Div 2" onclick="showDiv('2')" />
<input type="button" class="button" name="Showdiv3" value="Show Div 3" onclick="showDiv('3')" />
<div id="div1"> I'm div1 </div>
<div id="div2"> I'm div2 </div>
<div id="div3"> <form style="margin-top:1000px;height: 1000px;" id="form1">
Form with huge data in it
</form> </div>
DIV 3 페이지 아래 더 시작하는 긴 형식이있는 데모 : https://jsfiddle.net/cgrouge/Lx0pyg4L/
당신은 내가 같은 것을 사용하는 것이 좋습니다 것입니다 jQuery를 사용한다면 : 모든보다는하는'selected' 클래스를 사용, (먼저 선택한 내용의 위쪽 여백을 하차 JS 스타일 변경) 페이지의 해당 위치로 스크롤합니다 ('$ ('html, body'). scrollTop (선택한 항목 상단 여백))) – DBS