如何使用 jquery 向下滚动到 div 的特定子级
如何向下滚动到 div 的第 n 个子级。考虑这段代码
<span id="click_me">Click me to scroll down to nth child</span>
Messages div 有 6 个子级。我想向下滚动到第三个或第四个孩子,有人点击“click_me”
注意:孩子是动态添加的。使用一些 ajax 函数调用/主宰推送通知。
<div class="messages" id="messages_212">
<div class="message_container">
<p><b>Sahil grover: </b>5</p>
<div>
<div class="message_container">
<p><b>Sahil grover: </b>4</p>
<div>
<div class="message_container">
<p><b>Sahil grover: </b>3</p>
<div>
<div class="message_container">
<p><b>Sahil grover: </b>2</p>
<div>
<div class="message_container">
<p><b>Sahil grover: </b>1</p>
<div>
<div class="message_container">
<p><b>Sahil grover: </b>0</p>
<div>
</div>
How to scroll down to a nth child of a div. Consider this code
<span id="click_me">Click me to scroll down to nth child</span>
Messages div has 6 childs. I want to scroll down to 3rd or 4th child which somebody click on "click_me"
Note: Childs are added dynamically. Using some ajax functions calls/juggernaut push notifications.
<div class="messages" id="messages_212">
<div class="message_container">
<p><b>Sahil grover: </b>5</p>
<div>
<div class="message_container">
<p><b>Sahil grover: </b>4</p>
<div>
<div class="message_container">
<p><b>Sahil grover: </b>3</p>
<div>
<div class="message_container">
<p><b>Sahil grover: </b>2</p>
<div>
<div class="message_container">
<p><b>Sahil grover: </b>1</p>
<div>
<div class="message_container">
<p><b>Sahil grover: </b>0</p>
<div>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不使用 jQuery(或任何框架),但用纯 JavaScript 很容易做到:
I don't use jQuery (or any framework), but it's easy to do in plain JavaScript:
使用 http://plugins.jquery.com/project/ScrollTo
插件主页和文档:< a href="http://flesler.blogspot.com/2007/10/jqueryscrollto.html" rel="nofollow">http://flesler.blogspot.com/2007/10/jqueryscrollto.html
或
use http://plugins.jquery.com/project/ScrollTo
plugin homepage and docs at: http://flesler.blogspot.com/2007/10/jqueryscrollto.html
or
有一个 jQuery 插件: http://demos.flesler.com/jquery/scrollTo/
There is jQuery plugin for that: http://demos.flesler.com/jquery/scrollTo/