【问题标题】:ExtJS - How to highlight dom element permanently?ExtJS - 如何永久突出显示 dom 元素?
【发布时间】:2015-11-25 10:01:47
【问题描述】:

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

这里是Ext.dom.Element.highlight函数的常用用法:

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

Easing 可以,但我希望它以endColor 结束。

【问题讨论】:

    标签: extjs extjs4


    【解决方案1】:

    您可以拥有 afteranimate 侦听器事件并设置背景颜色。

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

    或者,如果你想创建这个功能,你可以覆盖 highlight 方法。

    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

    【讨论】:

    • field(或其子类如displayfield)没有setStyle功能;所以给出错误。
    • setFieldStyle 怎么样?
    • 是的,这正是我现在所做的。如果您编辑您的帖子,我想将其标记为正确答案。感谢您的指导。附言。 setFieldStyle 函数接受一个参数,它是 css-rule 和 value 的组合。目前它存在语法问题。
    • 很高兴它有帮助。我一般编辑了答案。但是,我们将值传递给 setFieldStyle,如下所示:'color: white;'
    猜你喜欢
    • 2020-06-17
    • 2017-05-30
    • 1970-01-01
    • 2023-03-18
    • 2014-12-02
    • 1970-01-01
    • 2014-11-14
    • 2013-01-07
    • 2017-10-17
    相关资源
    最近更新 更多