ExtJS - 如何永久突出dom元素?

时间:2015-11-25 10:01:47

标签: extjs extjs4

我想使用 Ext JS 突出显示dom元素永久

以下是Ext.dom.Element.highlight函数的常见用法:

field.getEl().highlight('#fbac3d', {
    attr: "backgroundColor",
    endColor: "#ffffff",
    easing: 'easeIn',
    duration: 4000
});

Easing没问题,但我希望以endColor结束。

1 个答案:

答案 0 :(得分:0)

您可以拥有afteranimate侦听器事件并设置backgroundColor。

field.getEl().highlight('#fbac3d', {
attr: "backgroundColor",
endColor: "#ffffff",
easing: 'easeIn',
duration: 4000,
listerners: {
    afteranimate: function() {
      // here you can set style attributes to your field
    }
}
});

或者,如果要创建此功能Universe,则可以覆盖突出显示方法。

Ext.dom.Element.override({
        highlight: function(color, o) {
        var me = this,
            dom = me.dom,
            from = {},
            restore, to, attr, lns, event, fn;

        o = o || {};
        lns = o.listeners || {};
        attr = o.attr || 'backgroundColor';
        from[attr] = color || 'ffff9c';

        if (!o.to) {
            to = {};
            to[attr] = o.endColor || me.getColor(attr, 'ffffff', '');
        }
        else {
            to = o.to;
        }

        // Don't apply directly on lns, since we reference it in our own callbacks below
        o.listeners = Ext.apply(Ext.apply({}, lns), {
            beforeanimate: function() {
                restore = dom.style[attr];
                var el = Ext.fly(dom, '_anim');
                el.clearOpacity();
                el.show();

                event = lns.beforeanimate;
                if (event) {
                    fn = event.fn || event;
                    return fn.apply(event.scope || lns.scope || WIN, arguments);
                }
            },
            afteranimate: function() {
                //Commented this , here it restores background color
                //if (dom) {
                //    dom.style[attr] = restore;
                //}

                event = lns.afteranimate;
                if (event) {
                    fn = event.fn || event;
                    fn.apply(event.scope || lns.scope || WIN, arguments);
                }
            }
        });

        me.animate(Ext.apply({}, o, {
            duration: 1000,
            easing: 'ease-in',
            from: from,
            to: to
        }));
        return me;
        }
    });

示例小提琴:https://fiddle.sencha.com/#fiddle/11mo