Javascript for when clicking on a link it simulates the down arrow key

Asked

Viewed 438 times

0

Good afternoon people, I’m having difficulties with a javascript, need to put a link where when clicking javascript simulates the down arrow.

 $(document).on('click', function (){
       //função clicar e simular seta para baixo
 });

Thanks in advance for the help.

  • 3

    Simulate the scroll?

  • No, I actually need the click to be the same as the arrow down on the keyboard.

  • Got it! Just a moment.

  • Thank you! I’ll be waiting.

  • 1

    Do you want this down arrow to affect what exactly? A autocomplete plugin? Simulating the key may not work depending on what you are trying to do. And it may have better paths.

  • Ready what I need is the following, I used html code, css and js for a site where the transition happens on the same screen. I tried using scroll javascript for the menu, but it didn’t work, so I thought of something like down arrow for the menu to work. follows the link of the site where it simulates the transition. https://codepen.io/suez/pen/gadLre

  • I used this code on a website and now I need to put a menu, using scroll code unfortunately does not work.

  • I don’t understand yet what you want. In this code the arrows are tied to roll the site a section up or down. The last snippet of the code does this (treating the event keydown).

  • @bfavaretto Thank you very much for your patience, let me see if I can explain better, I took a code from a page transition in Codepen.io where the transition happens on the main page. In addition to this effect I need to put a menu on the site, only the javascript using the scroll does not work. So I thought it could work with a click site function down.

  • I read the post, the comments and two different answers. Someone understood what the problem is?

  • @Aline sorry the confusion, I will try to research more to find a solution to this problem. Thanks guys for the force.

  • 2

    @Sidneiandrade, you can try to edit your question and be clearer as: What would you like to do exactly? If you have tried something and come close to what you want, add the code too. We want to help, but we don’t understand. = T One time I understood that, when clicked, you would like to scroll the screen to where there was the mouse click. Or that when you click on the screen, just scroll a little... asuhasu is not easy!

  • You want to open a menu with arrows and the code is conflicting? Is that it? Ideally would you [Dit] your question and include your own code, more explanations etc.

Show 8 more comments

2 answers

0

Would that be?

$("#clique").click(function() {
  $("html, body").animate({ scrollTop: $(document).height() }, 500);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<input type="button" id="clique" name="clique" value="clique">























<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<p>Teste</p>

  • this effect is the scroll, actually it would be something like Key Pressed, searching discovered that the Key Code of the down arrow is 40. I don’t know if this helps.

0

It would be something like that?

$("#foo").on('click', function (){
    jQuery.event.trigger({ type : 'keypress', which : 40 });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a id='foo' href="#">Teste</a>

  • John thank you so much for the answer, I thought it would solve the menu problem, but unfortunately it did not happen as I thought.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.