滚动到加载时重要的 li div 例如 li class="importants"
scroll to important li on load div for example li class="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
滚动到底部 !
试试这个:
$(document).ready(function() {
$('#comment').load('comment.php', function() {
$('#comments').animate({
scrollTop: $('#comments').find('.importants').offset().top
}, 400);
});
});
scrollTop: $('li .importants').offset().top
$(document).ready(function() {
$('#comment').load('comment.php', function() {
$("#comments").animate({scrollTop: $('.importants').offset().top - $("body").height() + 410});
});
});
但它只适用于您的网站!!
这是我的第一页:
<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
滚动到底部 !
试试这个:
$(document).ready(function() {
$('#comment').load('comment.php', function() {
$('#comments').animate({
scrollTop: $('#comments').find('.importants').offset().top
}, 400);
});
});
scrollTop: $('li .importants').offset().top
$(document).ready(function() {
$('#comment').load('comment.php', function() {
$("#comments").animate({scrollTop: $('.importants').offset().top - $("body").height() + 410});
});
});
但它只适用于您的网站!!