基于dragenter事件滚动?

时间:2018-03-20 11:50:40

标签: javascript jquery

如何逐步向上滚动并使用jquery逐步向下滚动。 (jquery ui不赞赏)。 我有2个divs

    <div class="upper" style="height:35px;background-color:red;right:0;left:0;top:0;position:fixed;width:100%;z-index:2000"></div>
    <div class="lower" style="height:35px;background-color:red;right:0;left:0;bottom:0;position:fixed;width:100%;z-index:2000"></div>

如果我拖动图像并将鼠标悬停在第一个div(上方)上,它应该逐步向上滚动。 如果我拖动并悬停在第二个div上,它应该手动向下滚动。

在这两种情况下,如果我离开div,滚动应该停止。

我正在尝试使用事件

来实现它
var isleftDragPosition=true;;
            $('.upper').on('dragleave', function(){
                console.log("hidragleave");
                var isleftDragPosition=true;
            });
            $('.lower').on('dragleave', function(){
                console.log("hi2dragleave")
                var isleftDragPosition=true;
            });
            $('.upper').on('dragenter', function(){
                var isleftDragPosition=false;
                while(!isleftDragPosition){
                    var x=document.documentElement.scrollTop;
                    console.log("to upper position",x);
                    window.scrollTo(0, x-2);
                }
            });
            $('.lower').on('dragenter', function(){
                console.log("hi2dragenter",document.documentElement.scrollTop)
                window.scrollTo(1000, 1000);
            });

我正在尝试使用顶部div向上滚动,但代码崩溃了我的标签(挂起)。

我怎么能这样做?

1 个答案:

答案 0 :(得分:0)

您正在重新定义每个处理程序中的标志,因此不会保存更改。此外,虽然循环可能是为了你的特定情况快。我修改了这样的代码:

main()

希望这有帮助。

相关问题