修复kindeditor编辑器中追加内容滚动条往上顶的bug

分类:ASP.NET     发布:2018-10-17     来源:本站     浏览:2422 次
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() {
		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 亲测有效~

如果觉得文章对您有帮助,您可以对我进行打赏 ¥1.31 元(金额随机^_^,每次刷新金额不同)。

请使用支付宝扫码支付

留言评论

*称  呼:
*联系方式: 方便与您取得联系,推荐使用邮箱。
*内  容:

已有评论

暂无数据

上一篇:常见文件MIME类型

下一篇:CSS实现元素居中原理解析