0

我遇到了一个问题,我想使用相同的功能在窗口内使用 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); }
                    });
                }
            }
            }

谢谢你的帮助

4

1 回答 1

1

看看下面一行:

var zone = $(this).prev();

它可能没有选择正确的元素来制作动画。没有您的 HTML 标记很难分辨,但您必须将其更改为不同的选择器。

由于您的.monter元素可能在滚动容器之前,请尝试将其更改为:

var zone = $(this).next();
于 2011-06-21T08:12:05.373 回答