How to make the screen scroll by clicking on a tag a

0

On the product page there are two links: 1 with the quantity of comments that already exist for the product and another saying "Write a comment". Further down the page there is a "tab" tab with the comments part. When you click on the link it triggers the comments tab, but does not slide the screen there so it seems that the link does nothing. What do I need to do to make this link have these two functions at the same time?

Note: I have tried to simply put # tab-review in href DOES NOT WORK

Links Code:

<a href="" onclick="$('a[href=\'#tab-review\']').trigger('click'); return false;"><?php echo $reviews; ?></a> / <a href="" onclick="$('a[href=\'#tab-review\']').trigger('click'); return false;"><?php echo $text_write; ?></a></p> 

Link to this page: link

    
asked by anonymous 15.01.2018 / 13:58

4 answers

1

Try to create a function in the click and call all actions within it, eg:

<a href="javascript:void(0)" onclick="scrollToComentarios()">Escreva um comentário</a>

<script>
function scrollToComentarios() {
    if ($('.product-tabs').length != 0) {
        $('a[href=\'#tab-review\']').trigger('click');
        $('#input-name').focus();  // adiciona foco ao primeiro input do form de comentarios
        $("html, body").animate({
            scrollTop: $('.product-tabs').offset().top
        }, 1000);
    }
}
</script>
    
15.01.2018 / 14:34
0

Hello. it's just you put it like this

<a href = '#Exemplo'>Vá para o paragrafo sobre JS</a>
<p id ="Exemplo" name="Exemplo">JS Java Script</p>

just put the link the same thing you put in the name and paragraph id you want to redirect the user

Follow a link if you still have questions link

    
15.01.2018 / 14:06
0

Place ID # tad-review in the reference of your link.

Ex:

<a href="#tab-review" onclick="$('a[href=\'#tab-review\']').trigger('click'); return false;"><?php echo $reviews; ?></a> / <a href="" onclick="$('a[href=\'#tab-review\']').trigger('click'); return false;"><?php echo $text_write; ?></a></p>
    
15.01.2018 / 14:07
0

Colleague, as the other alternatives did not work out, you can use ScrollTop together in your onclick. The code is:

$('html, body').scrollTop(0);

Suppose the place you want to go down is at 1200px from the top, then put that amount instead of zero:

$('html, body').scrollTop(1200);

In your code, it would look like this:

<a href="#tab-review" onclick="$('html, body').scrollTop(**1200**); $('a[href=\'#tab-review\']').trigger('click'); return false;"><?php echo $reviews; ?></a> / <a href="" onclick="$('a[href=\'#tab-review\']').trigger('click'); return false;"><?php echo $text_write; ?></a></p
    
15.01.2018 / 14:40