滚动到顶部按钮不起作用
问题描述:
我的博客是www.xperiblog.com 我有一个滚动到顶部按钮,它工作正常。 但最近我删除了我的文章导航脚本。现在该按钮不起作用。这里的代码滚动到顶部按钮不起作用
滚动到顶部的按钮CSS
/* CSS返回页首*/
#背到顶部{文本对齐:中心;背景:#f97e76;颜色:#FFF;溢出:隐藏; text-align:center; width:60px; height:30px; display:block; margin:0 auto; border-radius:5px 5px 0 0; border-top:3px solid#d26b64; cursor:pointer; background-image: URL(" http://4.bp.blogspot.com/-YQ-kX3Ifzb4/U6a5HhEhlLI/AAAAAAAADxI/wT_VI6RLrHM/s1600/totop.png");background-repeat:no-repeat;background-position:center;}
#后端到顶部的{颜色:#FFF;}
#后端到顶部:悬停{颜色:#F0F0F0;}
滚动到顶部按钮脚本
<script>
$("#back-to-top").click(function() {
$("html, body").animate({ scrollTop: 0 }, "slow");
return false;
});
</script>
脚本,我删除
<script type='text/javascript'>
var pageNaviConf = {
perPage: 5,
numPages: 5,
firstText: "First",
lastText: "Last",
nextText: "Next",
prevText: "Prev";
}
</script>
<script type='text/javascript'>
//<![CDATA[
function pageNavi(o){var m=location.href,l=m.indexOf("/search/label/")!=-1,a=l?m.substr(m.indexOf("/search/label/")+14,m.length):"";a=a.indexOf("?")!=-1?a.substr(0,a.indexOf("?")):a;var g=l?"/search/label/"+a+"?updated-max=":"/search?updated-max=",k=o.feed.entry.length,e=Math.ceil(k/pageNaviConf.perPage);if(e<=1){return}var n=1,h=[""];l?h.push("/search/label/"+a+"?max-results="+pageNaviConf.perPage):h.push("/?max-results="+pageNaviConf.perPage);for(var d=2;d<=e;d++){var c=(d-1)*pageNaviConf.perPage-1,b=o.feed.entry[c].published.$t,f=b.substring(0,19)+b.substring(23,29);f=encodeURIComponent(f);if(m.indexOf(f)!=-1){n=d}h.push(g+f+"&max-results="+pageNaviConf.perPage)}pageNavi.show(h,n,e)}pageNavi.show=function(f,e,a){var d=Math.floor((pageNaviConf.numPages-1)/2),g=pageNaviConf.numPages-1-d,c=e-d;if(c<=0){c=1}endPage=e+g;if((endPage-c)<pageNaviConf.numPages){endPage=c+pageNaviConf.numPages-1}if(endPage>a){endPage=a;c=a-pageNaviConf.numPages+1}if(c<=0){c=1}var b='<span class="pages">Pages '+e+' of '+a+"</span> ";if(c>1){b+='<a href="'+f[1]+'">'+pageNaviConf.firstText+"</a>"}if(e>1){b+='<a href="'+f[e-1]+'">'+pageNaviConf.prevText+"</a>"}for(i=c;i<=endPage;++i){if(i==e){b+='<span class="current">'+i+"</span>"}else{b+='<a href="'+f[i]+'">'+i+"</a>"}}if(e<a){b+='<a href="'+f[e+1]+'">'+pageNaviConf.nextText+"</a>"}if(endPage<a){b+='<a href="'+f[a]+'">'+pageNaviConf.lastText+"</a>"}document.write(b)};(function(){var b=location.href;if(b.indexOf("?q=")!=-1||b.indexOf(".html")!=-1){return}var d=b.indexOf("/search/label/")+14;if(d!=13){var c=b.indexOf("?"),a=(c==-1)?b.substring(d):b.substring(d,c);document.write('<script type="text/javascript" src="/feeds/posts/summary/-/'+a+'?alt=json-in-script&callback=pageNavi&max-results=99999"><\/script>')}else{document.write('<script type="text/javascript" src="/feeds/posts/summary?alt=json-in-script&callback=pageNavi&max-results=99999"><\/script>')}})();
//]]>
</script>
任何人都知道这里发生了什么。
答
我可以清除这个代码位,请参阅以下内容:
HTML
CSS
#back-to-top {
font-size: 18px !important;
position: fixed;
z-index: 9999;
color: #e60000;
cursor: pointer;
bottom: 2em;
right: 2em;
text-decoration: none;
transition: opacity 0.2s ease-out;
opacity: 0;
}
#back-to-top.show {
opacity: 1;
}
JS
if (jQuery('#back-to-top').length) {
var scrollTrigger = 100, // px
backToTop = function() {
var scrollTop = jQuery(window).scrollTop();
if (scrollTop > scrollTrigger) {
jQuery('#back-to-top').addClass('show');
} else {
jQuery('#back-to-top').removeClass('show');
}
};
backToTop();
jQuery(window).on('scroll', function() {
backToTop();
});
jQuery('#back-to-top').on('click', function (e) {
e.preventDefault();
jQuery('html,body').animate({
scrollTop: 0
}, 700);
});
的示例代码大吸盘似乎被网址编码,这是你的代码如何行事真的看起来?或只是复制粘贴错误? – DBS
我复制粘贴它 –
好吧,如果这就是你的js/css在你的编辑器中的外观,那么这就是你的问题。如果它只是一个复制粘贴错误,我建议修复这个问题,以便人们可以看到您的代码。 – DBS