我遇到了滚动条的问题,当我试图将div元素移动到屏幕底部(使用onmousedown,onmousemove,onmouseup函数)时,滚动条开始向下滚动,它看起来像溢出,如何使滚动条不向下移动,而我将元素移动到底部,只有当有溢出的文本或类似的东西时才滚动?有什么想法吗?
发布于 2013-05-24 07:31:10
在<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);https://stackoverflow.com/questions/16724999
复制相似问题