锚不起作用
Anchor doesn't work
我的 link 内页有问题。这是我在页面中使用的 jQuery 代码的一部分
$.fn.stopAtTop= function () {
var $this = this,
$window = $(window),
thisPos = $this.offset().top,
//thisPreservedTop = $this.css("top"),
setPosition,
under,
over;
under = function(){
if ($window.scrollTop() < thisPos) {
$this.css({
position: 'absolute',
top: ""
});
setPosition = over;
}
};
over = function(){
if (!($window.scrollTop() < thisPos)){
$this.css({
position: 'fixed',
top: 0
});
setPosition = under;
}
};
setPosition = over;
$window.resize(function()
{
bumperPos = pos.offset().top;
thisHeight = $this.outerHeight();
setPosition();
});
$window.scroll(function(){setPosition();});
setPosition();
};
这是一个例子DEMO
当我向下滚动时,一切正常,但当我想转到页面顶部时,这是不可能的。我知道问题是脚本修复了 div
,但我不知道如何修复它。有任何想法吗?
添加滚动到页面顶部的点击处理程序:
$("[href='#one']").click(function() {
scrollTo(0, 0);
});
我的 link 内页有问题。这是我在页面中使用的 jQuery 代码的一部分
$.fn.stopAtTop= function () {
var $this = this,
$window = $(window),
thisPos = $this.offset().top,
//thisPreservedTop = $this.css("top"),
setPosition,
under,
over;
under = function(){
if ($window.scrollTop() < thisPos) {
$this.css({
position: 'absolute',
top: ""
});
setPosition = over;
}
};
over = function(){
if (!($window.scrollTop() < thisPos)){
$this.css({
position: 'fixed',
top: 0
});
setPosition = under;
}
};
setPosition = over;
$window.resize(function()
{
bumperPos = pos.offset().top;
thisHeight = $this.outerHeight();
setPosition();
});
$window.scroll(function(){setPosition();});
setPosition();
};
这是一个例子DEMO
当我向下滚动时,一切正常,但当我想转到页面顶部时,这是不可能的。我知道问题是脚本修复了 div
,但我不知道如何修复它。有任何想法吗?
添加滚动到页面顶部的点击处理程序:
$("[href='#one']").click(function() {
scrollTo(0, 0);
});