WordPress添加前往顶部成果的办法

本文实例讲述了WordPress添加前往顶部成果的办法。分享给大家供大家参考。详细完成办法如下:

前往顶部成果不是WordPress自带的性能,这是一款js或jquery的成果,这里就来给大家引见在WordPress中添加反回顶部成果的办法.

**步:在上面主题文件footer.php底下加上这段代码:

<script src="top.js" type="text/javascript" charset="utf-8"></script >  
<p id="scroll"><a href="javascript:void(0)" onclick="goto_top()" title="前往顶部">TOP</a></p>

top.js代码如下:
//<![CDATA[  
var goto_top_type = -1;
var goto_top_itv = 0;
function goto_top_timer()
{
var y = goto_top_type == 1 ? document.documentElement.scrollTop : document.body.scrollTop;
var moveby = 15;
y -= Math.ceil(y * moveby / 100);
if (y < 0) {
y = 0;
}
if (goto_top_type == 1) {
document.documentElement.scrollTop = y;
}
else {
document.body.scrollTop = y;
}
if (y == 0) {
clearInterval(goto_top_itv);
goto_top_itv = 0;
}
}
function goto_top()
{
if (goto_top_itv == 0) {
if (document.documentElement && document.documentElement.scrollTop) {
goto_top_type = 1;
}
else if (document.body && document.body.scrollTop) {
goto_top_type = 2;
}
else {
goto_top_type = 0;
}
if (goto_top_type > 0) {
goto_top_itv = setInterval('goto_top_timer()', 50);
}
}
}
//]]>

第二步:在主题文件style.css文件中退出以下款式:
/*前往顶部*/  
#scroll {display:block; width:30px; margin-right:-380px;
position:fixed;
right:50%;
top:90%;
_margin-right:-507px;
_position:absolute;
_margin-top:30px;
_top:expression(eval(document.documentElement.scrollTop));
}
#scroll a {
display:block;
float:right;
padding:9px 5px;
cursor: pointer;
background-color:#444;
color:#fff;
border-radius:5px;
text-decoration: none;
font-weight:bold;
}
#scroll a:hover {
background-color:#333;
color:#669900;
text-decoration: none;
font-weight:bold;
}

这样咱们再肃清缓存是不是就能够看到有个前往顶部的成果按钮了,这样你的WordPress博客中的一切页面都会有前往顶部成果了.

心愿本文所述对大家的WordPress建站有所协助。

以上就是安达网络工作室关于《WordPress增加返回顶部效果的方法》的一些看法。更多内容请查看本栏目更多内容!

本文相关话题: WordPress 增加 返回顶部 效果 方法
版权声明:本文为 安达网络工作室 转载文章,如有侵权请联系我们及时删除。
相关文章
wordpress搬家预备/搬迁/解析工作

说到wordpress搬家,置信大局部wp玩家还是可以轻松处理成绩,可是关于老手置信会遇到不少费事成绩吧,上面跟...

wordpress非插件完成增加链接转跳性能

链接方式http://localhost/?go=http://www.baidu.com这种方式转跳的办法。 复制代码代码如下:add_action('w...

wordpress模板页面判别函数(本人整顿)

本人平常用到的一些函数,整顿一下,大家有用到来拿吧,我怕放电脑上不见了,当前又得找。 Index page 首页...

百度民间推出的WordPress构造化数据插件百度sitemap

就在discuz地图插件公布后不久,百度终于面向世界上最驰名的WordPress公布了地图插件!援用百度民间的引见,...

wordpress截取首页摘要内容的办法

本文实例讲述了在wordpress截取首页摘要内容完成办法,分享给大家供大家参考。详细剖析如下: 这里截取就是利...

WordPress文章题目链接增加正在加载中提醒的办法

本文实例讲述了WordPress文章题目链接增加正在加载中提醒的办法。分享给大家供大家参考。详细剖析如下: 咱...

需求提交

客服服务