jquery 向上(顶部),向下(底部)滑动


js代码部分:

window.onload = function(){
	var oTop = document.getElementById("goTop");
	var screenw = document.documentElement.clientWidth || document.body.clientWidth;
	var screenh = document.documentElement.clientHeight || document.body.clientHeight;
	var screenb = $(document).height(); 
	var oBottom = document.getElementById("goBottom");
	window.onscroll = function(){
		var scrolltop = document.documentElement.scrollTop || document.body.scrollTop;
		if(scrolltop-10 > 0){
			oTop.style.display = "block";
		}else{
			oTop.style.display = "none";
		}
		if(screenb - screenh - scrolltop < 15){
			oBottom.style.display = "none";
		}else{
			oBottom.style.display = "block";
		}
		
	}
	oTop.onclick = function(){
		//document.documentElement.scrollTop = document.body.scrollTop =0;
		$("html,body").animate({scrollTop:0},"slow");	
	}
	
	oBottom.onclick = function(){
		//document.documentElement.scrollTop = document.body.scrollTop =0;
		$("html,body").animate({ scrollTop:screenb  },"slow");
		
	}
}  	


2 html代码部分:

<div class="footer_fixed">
	            <a href="#gotop" class="go_top" id="goTop">go to top</a>
	            <a target="_blank" title="customer survey" href="'.Url::getUrl("contacts").'" class="cus_survey">customer survey</a>
	            <div class="ph"><a href="#gobottom" class="go_bottom" id="goBottom">go to bottom</a></div>
            </div>

3css部分:

.footer_fixed{position:fixed;right:22px;bottom:22px;z-index:99}
.go_top {
    height: 42px;
}
.go_top :hover{
	background-position: -45px 0px;
}
#goTop , .cus_survey, .go_bottom{
  background: url("../images/footer_fixed.png") no-repeat scroll 0 0 rgba(0, 0, 0, 0);
    display: block;
    height: 40px;
    margin: 0 0 -1px;
    text-indent: -999em;
    width: 43px;
}

.cus_survey {
    background-position: 0 -41px;
}
.cus_survey:hover{
	background-position: -45px -41px;
}
.go_bottom:hover{
	background-position: -45px -119px;
}
.footer_fixed .ph {
    display: block;
    height: 42px;
}
.go_bottom {
    background-position: 0 -119px;
    height: 43px;
}

4 背景图片:

http://img.dxcdn.com/combo/global/v5.0.2/img/footer_fixed.png












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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值