Comments à la “click to appear” with jQuery

2019-08-15 16:10发布

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!! ;)

4条回答
beautiful°
2楼-- · 2019-08-15 16:53

You can do it with Jquery as well.

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

Or you could use an anchor '#'

查看更多
劫难
3楼-- · 2019-08-15 16:59

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! :)

查看更多
Evening l夕情丶
4楼-- · 2019-08-15 17:01

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

查看更多
啃猪蹄的小仙女
5楼-- · 2019-08-15 17:07

Use document ready

<script type="text/javascript">
$(document).ready(function(){
    $("#showcomments").click(function () {
      $("#comments").slideToggle("slow");
    });
});
</script>
查看更多
登录 后发表回答