Comments à la “click to appear” with jQuery

拥有回忆 提交于 2019-12-24 07:04:58

问题


I have a WordPress blog and I'm trying to make that when a user clicks on "Show comments" the comments section appears with a simple animation.. I used

 <a href="#comments" id="showcomments">Show comments</a>

and then:

<script type="text/javascript">
jQuery(function(){
jQuery("#showcomments").click(function () {
    jQuery("#comments").slideToggle("slow");
});
});
</script>

<div id="comments" style="display:none">
    ......
    </div>

This is what I achieved (scroll down to "Commenta l'articolo!"): http://multiformeingegno.it/riflessioni/topserver-server-virtuali-made-italy/

As you can see if I click the link the comments section appears but the browser doesn't go down to the start of the section, you have to manually scroll down.. can you help me? Thanks!! ;)


回答1:


Above DIV id "comments", put the following code:

<a name="comments">

You need to point where you want the user to go after the click.

Good luck! :)




回答2:


You can do it with Jquery as well.

http://demos.flesler.com/jquery/scrollTo/

Or you could use an anchor '#'




回答3:


Use document ready

<script type="text/javascript">
$(document).ready(function(){
    $("#showcomments").click(function () {
      $("#comments").slideToggle("slow");
    });
});
</script>



回答4:


you need to put the target anchor in the comment box

<a name="comment" ></a>

This is what your link is looking for to focus on



来源:https://stackoverflow.com/questions/11162124/comments-%c3%a0-la-click-to-appear-with-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!