CKEDITOR如何识别滚动事件 [英] CKEDITOR how to Identify scroll event

查看:385
本文介绍了CKEDITOR如何识别滚动事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人知道如何抓住CKEDITOR的滚动事件?很容易识别变化和其他事件,但我无法cathc滚动事件..

Does anyone know how to catch the 'scroll' event in CKEDITOR? there is easy to identify change and other events, but I am unable to cathc Scroll event..

CKEDITOR.instances [i] .on 'change',function(){alert('text changed!');});

它不工作

CKEDITOR.instances [i] .on('scroll',function(){alert('I am scrolling! );});

有没有人知道一些解决方法?

does anyone know some workaround?

lot
M

Thx a lot M

推荐答案

首先你需要知道的是 CKEditor的实例(您从 CKEDITOR.instances 对象中获取)不是一个DOM元素。它确实触发了一些事件,如 更改 focus blur save ,但它们只是简单的或正面的更复杂的事情。

First thing you need to know is that CKEditor's instance (which you get from CKEDITOR.instances object) is not a DOM element. It indeed fires some events like change, focus, blur, or save, but they are just short cuts or facades to more complex things.

您想要添加一个DOM事件侦听器,那么您需要检索可编辑元素(编辑发生的元素)。它可以通过 editor.editable( ) 方法。然而,可编辑元素的棘手的事情是,它不总是可用,它不是准备就绪后,开始编辑器初始化,该编辑器可以替换这个元素与一个新的(通常在模式之间切换)。因此,编辑器触发 contentDom 通知新的可编辑项可用,并且可编辑项具有 attachListener 方法,与 on 清除可编辑的监听器。

Therefore, if you want to add a DOM event listener, then you need to retrieve the "editable" element (an element in which editing happens). It can be accessed by the editor.editable() method. However, the tricky thing about editable element is that it's not always available, it's not ready right after starting editor initialization and that editor may replace this element with a new one (usually after switching between modes). Therefore, editor fires a contentDom to notify that the new editable is available and the editable has an attachListener method which, unlike the on cleans the listener when editable is destroyed.

使用所有这些方法的方法在文档中解释,并有代码示例,但只是为了节省您一次点击:

The way to use all those methods is explained in the documentation and there are code samples, but just to save you one click:

editor.on( 'contentDom', function() {
    var editable = editor.editable();

    editable.attachListener( editable.getDocument(), 'scroll', function() {
        console.log( 'Editable has been scrolled' );
    });
});

更新:我忘记了'scroll'文档。我更新了上面的代码。

Update: I forgot that for 'scroll' event you have to listen on document. I updated the code above.

这篇关于CKEDITOR如何识别滚动事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆