内容在 jQuery 下拉动画完成之前出现
单击“阅读更多”链接后,我使用 jQuery 向下滑动并显示页面上的内容。动画效果很好,但在单击链接后、动画幻灯片之前立即显示正在显示的内容。有趣的是,我在其他一些网站上使用过这段代码,但从未遇到过这个问题。
这是代码:
<script type="text/javascript">
function ShowHide(){
$(".details").animate({"height": "toggle"}, { duration: 500 });
}
</script>
和 html
<div class="readmore"><a href="#" onclick="ShowHide(); return false;">More Info</a></div>
<div class="details">
<div class="description">
<div class="title">Description</div>
<p>content here</p>
<div class="title">Subscribe</div>
<a href="#">lorem</a><br />
<a href="#">lorem</a>
</div>
</div>
任何帮助都会很棒!另外,我可能希望在一页上有此幻灯片的多个实例。现在单击“阅读更多”链接将显示所有“详细信息”div。我将如何使这项工作仅在单个 div 上进行,而不必为每个实例编写新代码。我想要的一个例子是一个 WordPress 网站,它显示帖子列表中帖子的详细信息。
I'm using jQuery to slidedown and reveal content on my page after a "read more" link is clicked. The animation works well but the content that is being revealed appears immediately after the link is clicked, before the animated slidedown. The funny part is that I've used this code on a few other sites and never had this issue.
Here's the code:
<script type="text/javascript">
function ShowHide(){
$(".details").animate({"height": "toggle"}, { duration: 500 });
}
</script>
and the html
<div class="readmore"><a href="#" onclick="ShowHide(); return false;">More Info</a></div>
<div class="details">
<div class="description">
<div class="title">Description</div>
<p>content here</p>
<div class="title">Subscribe</div>
<a href="#">lorem</a><br />
<a href="#">lorem</a>
</div>
</div>
Any help would be great! Also on a side note, I may want to have multiple instances of this slidedown on one page. Right now clicking the "read more" link would reveal all the "details" divs. How would I go about making this work just on a single div without having to write new code for each instance. An example where I would want that would be a wordpress site that reveals details from a post in a list of posts.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
确保包含内容的
div
(在您的情况下为“details”类)也具有overflow:hidden
CSS 样式集。要回答你的第二个问题,你可以这样做:
另外,请确保在使用它时删除分配给链接的内联“onclick”处理程序。
Make sure that the
div
containing the content (in your case the one with the class "details") also has theoverflow: hidden
CSS style set.To answer your second question, you could do it as follows:
Also make sure to remove the inline "onclick" handler assigned to the link when using this.