2017-11-25 172 views
2

它我的第一页:滚动到负载DIV重要李例如李类= “importants”

<html> 
    <head> 
     <script type="text/javascript" src="js/jquery.min.js"></script> 
    </head> 
    <body> 
     <div id="comment"></div> 
     <script type="text/javascript"> 
      $(document).ready(function() { 
       $('#comment').load('comment.php'); 
      }); 
     </script> 
    </body> 
<html> 

而其comment.php:

<ul id="comments" style="overflow: scroll;"> 
    <li> 
     <p>comment</p> 
    </li> 
    <li> 
     <p>comment</p> 
    </li> 
    <li class="importants"> 
     <p>comment</p> 
    </li> 
    <li> 
     <p>comment</p> 
    </li> 
    <li> 
     <p>comment</p> 
    </li> 
    <li> 
     <p>comment</p> 
    </li> 
</ul> 

我想以后ul滚动到li.importants加载。 .importants用滚动显示评论。 (重要评论) 就这样ul滚动到底!

回答

0

,但它只是适合您的网站!

0

试试这个:

$(document).ready(function() { 
    $('#comment').load('comment.php', function() { 
     $('#comments').animate({ 
      scrollTop: $('#comments').find('.importants').offset().top 
     }, 400);  
    }); 
}); 
+0

它没有工作:( –

+0

它滚动到'#comments'结尾我想滚动到'.importants'! –

0
scrollTop: $('li .importants').offset().top