复制代码 代码如下:
.scroll-up {
background: #dcdcdc url('up.png') no-repeat center center;
width:48px !important; /*for ff and other standard browser*/
height:48px !important;
_width: 58px; /*for ie6 nonstandard box model*/
_height: 58px;
position: fixed;
_position: absolute; /*for ie6 fixed bug*/
opacity: .6;
filter: alpha(opacity=60); /*for ie opacity*/
padding:5px;
cursor: pointer;
display: none;
/*css3 property for ff chrome*/
border-radius:5px;
-webkit-transition-property: background-color, opacity;
-webkit-transition-duration: 1s;
-webkit-transition-timing-function: ease;
-moz-transition-property: background-color;
-moz-transition-duration: 1s;
-moz-transition-timing-function: ease;
}
.scroll-up:hover {
background-color:#b9b9b9;
opacity: .8;
}
下面是jquery代码
复制代码 代码如下:
;(function($) {
$.scrollbtn = function(options) {
var opts = $.extend({}, $.scrollbtn.defaults, options);
var $scrollbtn = $('
').css({
bottom: opts.bottom + 'px',
right: opts.right + 'px'
}).addclass('scroll-up').attr('title', opts.title)
.click(function() {
$('html, body').animate({scrolltop: 0}, opts.duration);
}).appendto('body');
// 绑定到window的scroll事件
$(window).bind('scroll', function() {
var scrolltop = $(document).scrolltop(),
viewheight = $(window).height();
// 小于配置的显示范围 则fadeout
if(scrolltop if($scrollbtn.is(':visible'))
$scrollbtn.fadeout(500);
// 大于配置的显示范围 则fadein
} else {
if($scrollbtn.is(':hidden'))
$scrollbtn.fadein(500);
}
// 解决ie6下css中fixed没有效果的bug
if(isie6()) {
var top = viewheight + scrolltop - $scrollbtn.outerheight() - opts.bottom;
$scrollbtn.css('top', top + 'px');
}
});
// 判断是否为ie6
function isie6() {
if($.browser.msie) {
if($.browser.version == '6.0') return true;
}
}
};
/**
* -params
* -showscale: scroll down how much to show the scrollup button
* -right: to right of scrollable container
* -bottom: to bottom of scrollable container
*/
$.scrollbtn.defaults = { // 默认值
showscale: 100, // 超过100px 显示按钮
right:10,
bottom:10,
duration:200, // 回到页面顶部的时间间隔
title:'back to top' // div的title属性
}
})(jquery);
$.scrollbtn({
showscale: 200, //下滚200px后 显示按钮
bottom:20, // 靠底部20px
right:20 // 靠右部20px
});
backtotop.rar
