【问题标题】:Run AngularJS directive after TypeKit loads font在 TypeKit 加载字体后运行 AngularJS 指令
【发布时间】:2014-09-04 00:10:25
【问题描述】:

我写了一个指令,它给了我一段文本的位置,但位置不正确,因为指令在 TypeKit 应用字体之前触发。

app.directive('myDirective', function(){
    return {
        restrict: 'A',
        link: function(scope, elem, attrs){

            var active = elem.children('li.active');
            console.log( active[0].offsetLeft ); // <-- This is wrong

            elem.bind('click', function(){
                var active = elem.children('li.active');
                console.log( active[0].offsetLeft ); // <-- This is correct
            });
        }
    };
});

关于如何在字体加载后触发我的指令有什么想法吗?

【问题讨论】:

    标签: angularjs typekit


    【解决方案1】:

    实际上,我是个笨蛋——看起来这只会在本地工作时失败。一旦我推送到服务器,问题就解决了。

    【讨论】:

      猜你喜欢
      • 2020-06-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-25
      相关资源
      最近更新 更多