移动div元素javascript时停止滚动

时间:2013-05-23 22:35:25

标签: javascript html scrollbar mouse

我遇到滚动条的问题,当我试图将div元素移动到屏幕的底部时(使用onmousedown,onmousemove,onmouseup函数)滚动条开始向下滚动,它看起来像溢出,如何使滚动条不向下移动而我将元素移动到底部并仅在有文本溢出或者像某样的情况下滚动?任何想法??

1 个答案:

答案 0 :(得分:0)

切换<html><body>上的CSS类,在移动元素时将overflow属性设置为hidden

不太确定您的实现看起来如何,但这些内容如下:

CSS

.whileMoving { 
    overflow:hidden;
}

的Javascript

var foo  = document.getElementById('yourDiv'), 
    html = document.getElementsByTagName('html')[0],
    body = document.getElementsByTagName('body')[0];

foo.addEventListener('onmousedown', function(){
    body.className = "whileMoving";
    html.className = "whileMoving";
},false);

// Then, remove the class on mouse up.

foo.addEventListener('onmouseup', function(){
    body.className = "";
    html.className = "";
},false);
相关问题