2014-10-04 39 views
0
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script> 
<script> 
jQuery(document).ready(function($) { 
    window.scroll(0, document.documentElement.scrollHeight); 
}); 
</script> 
</head> 
<body> 
    <div id="hahaha"> 
     <% for (int i = 0 ; i < 100 ; i++) {%> 
      <div><%=i%></div> 
     <% } %> 
    </div> 
     <% for (int i = 0 ; i < 100 ; i++) {%> 
     <div><%=i%></div> 
    <% } %> 
</body> 

CSS:如何向下滚动到div标签内部项目的底部?

div#hahaha{ 
    background-color: #EEEEEE; 
    position: absolute; 
    width:500px; 
    height:200px; 
    overflow-y: scroll; 
} 

这个代码仅适用其位于浏览器右侧的主滚动条上,而是在div标签内不工作,任何人都可以告诉我怎么做位于div内的内容滚动到底部?

回答

0

使用jQuery,你可以这样来做:

var bottom= $('div').height()+$('div').prop('scrollHeight');  
$('div').scrollTop(bottom); 

,或者如果你想制作动画:

var bottom= $('div').height()+$('div').prop('scrollHeight');  
$('div').animate({scrollTop:bottom},500); 
0

这里是你可以使用OffsetPosition找到的位置的例子您要滚动的div

使用offset

JS fiddle

usign position

JS fiddle

$(window).load(function() { 
    var pos = $('.scrollhere').position() // or .offset 
    var toppos = pos.top 
    $('#scrolling').stop().animate({ 
     'scrollTop': toppos 
    }, 1000) 
})