Home  >  Article  >  Web Front-end  >  jquery implements keyboard left and right page turning effects_jquery

jquery implements keyboard left and right page turning effects_jquery

WBOY
WBOYOriginal
2016-05-16 16:01:271220browse

jquery keyboard turns pages left and right, jquery keyboard direction keys page turning function, when there is no previous or next article, there will be no response when pressing the keyboard to avoid wrong jumps.

HTML code

<p>上一篇:<a id='pre' href='http://www.daimajiayuan.com/sitejs-17294-1.html'>一款随滚动条下滑左右渐入的页面布局</a> </p> 
<p>下一篇:<a id='next' href='http://www.daimajiayuan.com/sitejs-18339-1.html'>点击复选框添加或删除value值到input输入框中</a> </p> 

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

The above is the entire content of this article, I hope you all like it.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn