織夢CMS教程之實現(xiàn)按鍵盤方向鍵上一頁/下一頁翻頁效果,這樣可以提高用戶體驗,特別是在小說站和圖片站中用的比較多。
DEDECMS實現(xiàn)鍵盤翻頁的制作方法:
找到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> ";
<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=bookpage
if (event.keyCode==13) location=index_page
if (event.keyCode==37)
{
if (prevpage!='' && prevpage!='沒有了 ')
location=prevpage;
else
alert('這是第一頁');
}
if (event.keyCode==39)
{
if (nextpage!='' && nextpage!='下一篇:沒有了 ')
location=nextpage;
else
alert('已經(jīng)是最后一頁了');
}
}
//-->
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){//IE
try{
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>
可以當單獨將此JS放到JS文件中調(diào)用,防止頁面臃腫保持html源碼的簡介,用按鍵實現(xiàn)翻頁效果就可以了,趕緊測試下吧
版權(quán)聲明: 本站資源均來自互聯(lián)網(wǎng)或會員發(fā)布,如果侵犯了您的權(quán)益請與我們聯(lián)系,我們將在24小時內(nèi)刪除!謝謝!
轉(zhuǎn)載請注明: 織夢CMS實現(xiàn)按鍵盤方向鍵翻頁效果