DEDECMS教程之实现按键盘方向键实现上一页/下一页翻页效果,这样可以提高用户体验,特别是在小说站和图片站中用的比较多。DEDECMS教程之键盘翻页的制作方法:
打开 include/arc.archives.class.php 查找到以下代码:$this->PreNext['pre'] = "上一篇:<a href='$mlink'>{$preRow['title']}</a> ";替换成以下代码:$this->PreNext['pre'] = "$mlink ";$this->PreNext['next'] = "下一篇:<a href='$mlink'>{$nextRow['title']}</a> ";
然后在内容页用js进行调用,代码如下:<script type="text/javascript" language="javascript"><!--document.onkeydown=nextpage;var prevpage='{dede:prenext get='pre'/}';var nextpage='{dede:prenext get='next'/}';var index_page = "index.html";//var bookpage="index.html";function nextpage(event){event = event ? event : (window.event ? window.event : null);//if (event.keyCode==13) location=bookpageif (event.keyCode==13) location=index_pageif (event.keyCode==37){if (prevpage!='' && prevpage!='上一篇:没有了 ')location=prevpage;elsealert('这是第一页');}if (event.keyCode==39){if (nextpage!='' && nextpage!='下一篇:没有了 ')location=nextpage;elsealert('已经是最后一页了');}}//-->function getElement(aID){return (document.getElementById) ? document.getElementById(aID): document.all[aID];}function makeRequest(url){http_request=false;if(window.XMLHttpRequest){//Mozilla,Safari,...http_request=new XMLHttpRequest();if(http_request.overrideMimeType){http_request.overrideMimeType('text/xml');}}else if(window.ActiveXObject){//IEtry{http_request=new ActiveXObject("Msxml2.XMLHTTP");}catch(e){try{http_request=new ActiveXObject("Microsoft.XMLHTTP");}catch(e){}}}if(!http_request){alert('Giving up:(Cannot create an XMLHTTP instance)');return false;}return http_request;}</script>加入到文章模版的<body>标签之前的内容就行了。当然为了防止页面代码臃肿,大家可以将此代码放在单独JS文件中采用外部调用即可,保持页面简洁清爽。DEDECMS教程之实现按键盘方向键实现上一页/下一页翻页效果制作完毕!