kindeditor编辑器中追加内容滚动条往上顶的bug
如题 kindeditor编辑器中追加内容滚动条往上顶的bug 无论滚动条拉到什么地方,一复制粘贴,插入图片,等操作,就会跑到最顶部,所以操作起来很不方便,各位有没有知道这个问题怎么解决???
遇到这个问题是因为使用了br换行引起的。默认使用p标签换行没有这个bug
因为加了换行符号的原因 newlineTag: ‘br’,
KindEditor.ready(function(K) {
editor = K.create('textarea[name="content"]', {
allowFileManager : true,
newlineTag : "br" //或者为"p" //使用br换行
});
});
我调试了一下, 找到了问题的原因!!!
版本 4.1.10 kindeditor.js 第 1514 行这个函数 box.top 是负数了, 然而这个函数返回后, 第 2763 行执行了 win.scrollTo(pos.x, pos.y); 滚动滚动条.
pos : function() {
pos : function() {
var self = this, node = self[0], x = 0, y = 0;
if (node) {
if (node.getBoundingClientRect) {
var box = node.getBoundingClientRect(),
pos = _getScrollPos(self.doc);
x = box.left + pos.x;
y = box.top + pos.y;/*此top为负数*/
} else {
while (node) {
x += node.offsetLeft;
y += node.offsetTop;
node = node.offsetParent;
}
}
}
return {x : _round(x), y : _round(y)};
},
没有找到特别好的解决方案,临时解决一下。
这样滚动条就无法自动滚动了,尽管不完美,但比滚动条总往上顶强。
ps:如果不使用 br 换行完全不会产生这个bug
解决代码如下:
pos : function() {
var self = this, node = self[0], x = 0, y = 0;
if (node) {
if (node.getBoundingClientRect) {
var box = node.getBoundingClientRect(),
pos = _getScrollPos(self.doc);
x = box.left + pos.x;
//y = box.top + pos.y;
//临时解决方案 针对 newlineTag: 'br',
y = pos.y;
} else {
while (node) {
x += node.offsetLeft;
y += node.offsetTop;
node = node.offsetParent;
}
}
}
return {x : _round(x), y : _round(y)};
},