我正在使用 raphael 在屏幕上绘制元素。我的绘图对象容器包含在 div
和 overflow:scroll
中。在所有浏览器中除了 IE 7/8,当用户绘图时,它不会滚动。然而,在 IE 7/8 中,当用户拖动(即画一条线)时,它会在用户接近边缘时自动滚动。我找到了一些有关 jQuery 的帮助,并尝试覆盖 div 的 onscroll
事件,但这不起作用。
我没有使用 jQuery,无法添加它。
最佳答案
有时滚动是由“选择”窗口中的文本引起的(在此页面上单击并从上到下拖动以了解我的意思)。如果没有看到jsFiddle,我无法从您的描述中判断这是否是问题所在。示例或示例代码,但您可以尝试禁用选择。
正如您提到的,jQuery 不适合您。如果是的话,你只需使用 disableSelection()
.
对于普通的 Javascript 解决方案,请尝试:
function disableSelection(target) {
if (typeof target.onselectstart != "undefined") { //IE
target.onselectstart = function () {
return false;
};
} else if (typeof target.style.MozUserSelect != "undefined") { //Firefox
target.style.MozUserSelect = "none";
} else { //All other ie: Opera
target.onmousedown = function () {
return false;
};
}
target.style.cursor = "default";
}
window.onload = function () {
disableSelection(document.body);
};
来源(为清楚起见略有修改):Disable selection on browser using Javascript
关于javascript - 拖动 HTML 时防止自动滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15435375/