返回顶部简易代码
直接放js就可以显示
(function() {
var btnId = '__gotop';
var isIE = !!window.ActiveXObject && /msie (d)/i.test(navigator.userAgent) ? RegExp['$1'] : false;
function $() {
return document.getElementById(arguments[0]);
}
function getScrollTop() {
return ('pageYOffset' in window) ? window.pageYOffset
: document.patMode === "Backpat"
&& document.body.scrollTop
|| document.documentElement.scrollTop ;
}
function bindEvent(event, func) {
if (window.addEventListener) {
window.addEventListener(event, func, false);
} else if (window.attachEvent) {
window.attachEvent('on' + event, func);
}
}
bindEvent('load',
function() {
var css = 'background-color:#999;width:50px;height:50px;position:fixed;right:20px;bottom:30px;border-radius:10px;cursor:pointer;display:none;';
if (isIE && isIE < 7) {
css += '_position:absolute;_top:expression(eval(document.documentElement.scrollTop+document.documentElement.clientHeight-30-this.offsetHeight-(parseInt(this.currentStyle.marginTop,10)||0)-(parseInt(this.currentStyle.marginBottom,10)||0)))';
var style = document.createStyleSheet();
style.cssText = '*html{background-image:url(about:blank);background-attachment:fixed;}';
}
var html = '<div style="height: 0;width: 0;border:14px solid #999999;border-top: 0 none;border-bottom:14px solid #fff;position: relative;margin:12px 0 0 11px;"><div style="width:8px;height:7px;position:absolute;top:14px;left:-4px;background-color:#fff;overflow: hidden;"></div></div>';
var el = document.createElement('DIV');
el.id = btnId;
el.style.cssText = css;
el.innerHTML = html;
document.body.appendChild(el);
el.onclick = function() {
(function() {
var top = getScrollTop();
if (top > 0) {
window.scrollTo(0, top / 1.2)
setTimeout(arguments.callee, 10);
}
})();
};
el.onmouseover = function() {
$(btnId).firstChild.style.borderBottom = '14px solid #ddd';
$(btnId).firstChild.firstChild.style.backgroundColor = '#ddd';
};
el.onmouseout = function() {
$(btnId).firstChild.style.borderBottom = '14px solid #fff';
$(btnId).firstChild.firstChild.style.backgroundColor = '#fff';
};
}
);
bindEvent('scroll',
function() {
var top = getScrollTop(), display = 'none';
if (top > 0) {
display = 'block';
}
if ($(btnId)) $(btnId).style.display = display;
});
})();
声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至201542412@QQ.com举报,一经查实,本站将立刻删除。
相关推荐
-
帝国CMS内容页附件中文显示或者显示代码名称下载
在帝国CMS模板制作中,比如内容页面显示该内容的附件地址,必须显示原始路径地址,或者说想要中文的路径地址。那么就要用以下方法来实现了:
-
jQuery点击加载更多按钮加载图片效果代码下载
jQury点击加载更多按钮加载图片效果代码下载
-
html中复选框checked默认勾选 设置默认选中代码
html中复选框Chckbox设置默认选中代码[cod][cod]注意:chckd=”chckd”表示默认选中状态。
-
杰奇CMS清空所有小说的数据库代码
删除TXT重新采集,重新采集后居然发现..............小说ID不是从......1......开始;这咋办?重新安装杰奇呗?这也是一个办法,但是我们有个更好的办法就是删除数据库的ID...
-
利用jQuery实现点击弹出登录注册表单代码
利用jQury实现点击弹出登录注册表单代码