遇到这个问题是因为使用了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() { 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)}; }没有找到特别好的解决方案,临时解决一下。
解决代码如下:
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)}; },转自:http://www.lrxin.com/archives-1097.html 亲测有效~