随网页上下移动的返回顶部按钮如何实现

tangguowei 2009-12-07 05:45:14
一开始按钮图片在一个位置,移动滚动条后,能上下移动,始终在一个固定区域移动用jquery怎么实现

如http://www.mofang.cn/_about/about.php右侧的top做法,

$(window).scroll(function (){
var oldTop = parseInt($('#gotop').css('top'));
var newTop = $(document).scrollTop() + 200;
$('#gotop').animate({top:newTop},10);
//alert(currentTop);
});
我这样写的效果不一样
...全文
464 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
lijing1116 2009-12-07
  • 打赏
  • 举报
回复
学习学习
chen_xiangguo 2009-12-07
  • 打赏
  • 举报
回复
xmliy 2009-12-07
  • 打赏
  • 举报
回复
对于IE7.0以上版本或其它标准浏览器,可以使用display:fixed来设置
qqzeng-ip 2009-12-07
  • 打赏
  • 举报
回复
keepfixed:function(){
var $window=jQuery(window)
var controlx=$window.scrollLeft() + $window.width() - this.$control.width() - this.controlattrs.offsetx
var controly=$window.scrollTop() + $window.height() - this.$control.height() - this.controlattrs.offsety
this.$control.css({left:controlx+'px', top:controly+'px'})
},

togglecontrol:function(){
var scrolltop=jQuery(window).scrollTop()
if (!this.cssfixedsupport)
this.keepfixed()
this.state.shouldvisible=(scrolltop>=this.setting.startline)? true : false
if (this.state.shouldvisible && !this.state.isvisible){
this.$control.stop().animate({opacity:1}, this.setting.fadeduration[0])
this.state.isvisible=true
}
else if (this.state.shouldvisible==false && this.state.isvisible){
this.$control.stop().animate({opacity:0}, this.setting.fadeduration[1])
this.state.isvisible=false
}
},

init:function(){
jQuery(document).ready(function($){
var mainobj=scrolltotop
var iebrws=document.all
mainobj.cssfixedsupport=!iebrws || iebrws && document.compatMode=="CSS1Compat" && window.XMLHttpRequest //not IE or IE7+ browsers in standards mode
mainobj.$body=(window.opera)? (document.compatMode=="CSS1Compat"? $('html') : $('body')) : $('html,body')
mainobj.$control=$('<div id="topcontrol">'+mainobj.controlHTML+'</div>')
.css({position:mainobj.cssfixedsupport? 'fixed' : 'absolute', bottom:mainobj.controlattrs.offsety, right:mainobj.controlattrs.offsetx, opacity:0, cursor:'pointer'})
.attr({title:'Scroll Back to Top'})
.click(function(){mainobj.scrollup(); return false})
.appendTo('body')
if (document.all && !window.XMLHttpRequest && mainobj.$control.text()!='') //loose check for IE6 and below, plus whether control contains any text
mainobj.$control.css({width:mainobj.$control.width()}) //IE6- seems to require an explicit width on a DIV containing text
mainobj.togglecontrol()
$('a[href="' + mainobj.anchorkeyword +'"]').click(function(){
mainobj.scrollup()
return false
})
$(window).bind('scroll resize', function(e){
mainobj.togglecontrol()
})
})
}
}
happy664618843 2009-12-07
  • 打赏
  • 举报
回复

var advTop=0;
function init()
{
advTop=document.getElementById("advlayer").style.pixelTop;

}
function move()
{
document.getElementById("advlayer").style.pixelTop=advTop+document.documentElement.scrollTop;
}

87,994

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧