html中置顶的功能实现,实现置顶功能jQuery

HTML:

CSS:

.fl{

display:block;

float:left;

width:50px;

height:50px;

text-align:center;

background-color:#eaeaea;

background-image:url(../images/toTop.png);

}

.fl:hover{background-color:#f48942;background-image:url(../images/toTop.png);}

#Fixed {

position: fixed;

_position: absolute;

z-index: 100;

bottom: 70px;

left: 50%;

margin-left: 530px;

_bottom: auto;_top:

expression(document.documentElement.scrollTop+document.documentElement.clientHeight-this.offsetHeight-70);

width: 50px;

text-indent: -40000px;

background: #fff

}

/*置顶 end*/

Js:

/*置顶功能*/

$(function(){

$(window).bind('scroll', {

fixedOffsetBottom: parseInt($('#Fixed').css('bottom'))

},

function(e) {

var scrollTop = $(window).scrollTop();

var referFooter =$('#footer');

scrollTop > 100 ? $('#goTop').show() : $('#goTop').hide();

if (!/msie 6/i.test(navigator.userAgent)) {

if ($(window).height() - (referFooter.offset().top - $(window).scrollTop()) > e.data.fixedOffsetBottom) {

$('#Fixed').css('bottom', $(window).height() - (referFooter.offset().top - $(window).scrollTop()))

} else {

$('#Fixed').css('bottom', e.data.fixedOffsetBottom)

}

}

});

$('#goTop').click(function() {

$('body,html').stop().animate({

'scrollTop': 0,

'duration': 100,

'easing': 'ease-in'

})

});

});

/*置顶功能 end*/

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值