jQuery realizes page turning effect by pressing the keyboard direction key

  • 2020-05-16 06:24:10
  • OfStack

1. jQuery code:


$(document).ready(function(){
    var prevpage=$("#pre").attr("href");
    var nextpage=$("#next").attr("href");
    $("body").keydown(function(event){
      if(event.keyCode==37 && prevpage!=undefined) location=prevpage;
      if(event.keyCode==39 && nextpage!=undefined) location=nextpage;
    });
 });

2. Html code:


<p>
on 1 Article:
<a id='pre' href='//www.ofstack.com/sitejs-17294-1.html'>1 With the scroll bar sliding left and right gradually into the page layout </a>
</p>
<p>
Under the 1 Article:
<a id='next' href='//www.ofstack.com/sitejs-18339-1.html'> Click the check box to add or remove value Value to the input In the input box </a>
</p>

Remember to introduce jQuery files, ok here is no more nonsense, I hope this article can help you learn jQuery.


Related articles: