函数 ScrollTop 仅以一种方式工作
我遇到了一个问题,我想使用相同的函数在窗口内向上滚动,使用 ScrollTop,但“0”或“-=10”不起作用。你明白为什么吗?如果我发出警报,它会识别“monter”类,但它永远不会上升到“0”或“-=10”。这是我的代码:
function scroll_descendre(){
var scrolling;
$('.descendre, .monter').bind({
mousedown: function(){
var zone = $(this).prev();
scrolling = true; //this is here :
if ($(this).attr('class')=='descendre') startScrolling(zone, '+=20');
else if($(this).attr('class')=='monter') startScrolling(zone, '0');
},
mouseup: function(){
scrolling = false;
},
click: function(e){
e.preventDefault();
}
});
function startScrolling(obj, param){
if (!scrolling) {
obj.stop();
} else {
obj.animate({"scrollTop": param}, "fast", function(){
if (scrolling) { startScrolling(obj, param); }
});
}
}
}
感谢您的帮助
i'm stuck on a problem, i would like to use the same function to go up inside a window, with ScrollTop, but the "0" or "-=10" does not work. Do you understand why? If i put an alert, it recognizes the class "monter", but it never goes up to "0" or "-=10". Here is my code :
function scroll_descendre(){
var scrolling;
$('.descendre, .monter').bind({
mousedown: function(){
var zone = $(this).prev();
scrolling = true; //this is here :
if ($(this).attr('class')=='descendre') startScrolling(zone, '+=20');
else if($(this).attr('class')=='monter') startScrolling(zone, '0');
},
mouseup: function(){
scrolling = false;
},
click: function(e){
e.preventDefault();
}
});
function startScrolling(obj, param){
if (!scrolling) {
obj.stop();
} else {
obj.animate({"scrollTop": param}, "fast", function(){
if (scrolling) { startScrolling(obj, param); }
});
}
}
}
Thanks for your help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看一下下面的行:
它可能没有选择正确的元素来设置动画。如果没有 HTML 标记,很难判断,但您必须将其更改为不同的选择器。
由于您的
.monter
元素可能位于滚动容器之前,请尝试将其更改为:Have a look at the following line:
It might not be selecting the right element to animate. It's hard to tell without your HTML markup, but you have to change it to a different selector.
As your
.monter
element might be before the scrolling container, try changing it to: