1. <legend id='3RnZ3'><style id='3RnZ3'><dir id='3RnZ3'><q id='3RnZ3'></q></dir></style></legend>

  2. <small id='3RnZ3'></small><noframes id='3RnZ3'>

      <bdo id='3RnZ3'></bdo><ul id='3RnZ3'></ul>
    <tfoot id='3RnZ3'></tfoot>
    <i id='3RnZ3'><tr id='3RnZ3'><dt id='3RnZ3'><q id='3RnZ3'><span id='3RnZ3'><b id='3RnZ3'><form id='3RnZ3'><ins id='3RnZ3'></ins><ul id='3RnZ3'></ul><sub id='3RnZ3'></sub></form><legend id='3RnZ3'></legend><bdo id='3RnZ3'><pre id='3RnZ3'><center id='3RnZ3'></center></pre></bdo></b><th id='3RnZ3'></th></span></q></dt></tr></i><div id='3RnZ3'><tfoot id='3RnZ3'></tfoot><dl id='3RnZ3'><fieldset id='3RnZ3'></fieldset></dl></div>

    1. AngularJS - 指令渲染完成后如何查询 DOM

      AngularJS - How to query the DOM when directive rendering is complete(AngularJS - 指令渲染完成后如何查询 DOM)
      <tfoot id='kgnqV'></tfoot>
        <bdo id='kgnqV'></bdo><ul id='kgnqV'></ul>
            <tbody id='kgnqV'></tbody>
          <legend id='kgnqV'><style id='kgnqV'><dir id='kgnqV'><q id='kgnqV'></q></dir></style></legend>

              <i id='kgnqV'><tr id='kgnqV'><dt id='kgnqV'><q id='kgnqV'><span id='kgnqV'><b id='kgnqV'><form id='kgnqV'><ins id='kgnqV'></ins><ul id='kgnqV'></ul><sub id='kgnqV'></sub></form><legend id='kgnqV'></legend><bdo id='kgnqV'><pre id='kgnqV'><center id='kgnqV'></center></pre></bdo></b><th id='kgnqV'></th></span></q></dt></tr></i><div id='kgnqV'><tfoot id='kgnqV'></tfoot><dl id='kgnqV'><fieldset id='kgnqV'></fieldset></dl></div>
              1. <small id='kgnqV'></small><noframes id='kgnqV'>

                本文介绍了AngularJS - 指令渲染完成后如何查询 DOM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在尝试使用 AngularJS 指令实现自定义滚动窗格组件.在下面的

                很遗憾,无法确定渲染何时完成(例如,没有事件).使用 $timeout 似乎是最好的解决方法.

                在上面的链接中,@Nik 在评论中提到他正在检查 $('tr').length >3,针对他的特定场景,确定渲染何时完成.也许您可以定期检查 DOM 中的某些内容以确定渲染是否完成.

                I'm trying to implement a custom scroll pane component using an AngularJS directive. in the following jsfiddle example I have an example of the basic prototype.

                here is a schema of my idea:

                Here is the directive code:

                    myApp.directive('lpScrollPane', function factory() {
                    return {
                        restrict: 'A',
                        replace: true,
                        transclude: true,
                        template: '<div class="scrollPaneWrapper"><div class="scrollPane" ng-transclude></div><div class="thumbTrack" ></div></div>',
                        compile: function (tElement, tAttrs) {
                            var minHeight = 30;
                            return function (scope, iElement, iAttrs) {
                                var thumbTrack = angular.element(iElement.children()[1]);
                
                                scope.onScrollHeight = function () {
                                    console.log(iElement.children()[0].scrollHeight);
                
                                    var H1 = iElement[0].offsetHeight;
                                    var H2 = iElement.children()[0].scrollHeight;
                                    if (H2 > H1) {
                                        var trackHeight = Math.round(minHeight + (H1 - minHeight) * (1 - Math.pow((H2 - H1) / H2, 0.8)));
                                        thumbTrack.css({
                                            display: "block",
                                            height: trackHeight + "px"
                                        });
                                        console.log(H2, H1, trackHeight);
                                    } else {
                                        thumbTrack.css({
                                            display: "none"
                                        });
                                    }
                                };
                
                                scope.$watch(function () {
                                    scope.onScrollHeight();
                                    //setTimeout(scope.onScrollHeight, 100)
                                });
                
                
                            }
                        }
                    };
                });
                

                Basically there are 2 dives 1 with overflow hidden and one with overflow scroll and another div to mimic the thumb tracker.

                My Goal is to monitor the scrollHeight property and then change the tracker height accordingly. the issue is the $watch gets fired before the DOM is rendered so there is a delay in showing and calculating the tracker. For now I used setTimeout on the watch function and it works fine (un-comment line 35 and comment 34 to see it in action).

                What would be the right way to do it?

                解决方案

                See is there a post render callback for Angular JS directive?

                Unfortunately, there is no way to determine when rendering is complete (e.g., there is no event). Using $timeout seems to be the best workaround available.

                In the link above, @Nik mentioned in a comment that he was checking $('tr').length > 3, for his particular scenario, to determine when rendering was complete. Maybe there is something you could periodically examine in the DOM to determine that rendering is complete.

                这篇关于AngularJS - 指令渲染完成后如何查询 DOM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Pause youtube video, youtube api(暂停 youtube 视频,youtube api)
                Youtube iframe api not triggering onYouTubeIframeAPIReady(Youtube iframe api 未触发 onYouTubeIframeAPIReady)
                How can I stop a video with Javascript in Youtube?(如何在 Youtube 中停止使用 Javascript 的视频?)
                How to call Greasemonkey#39;s GM_ functions from code that must run in the target page scope?(如何从必须在目标页面范围内运行的代码中调用 Greasemonkey 的 GM_ 函数?)
                How do you mute an embedded Youtube player?(如何使嵌入式 Youtube 播放器静音?)
                How to get number of video views with YouTube API?(如何使用 YouTube API 获取视频观看次数?)

                <legend id='RSB51'><style id='RSB51'><dir id='RSB51'><q id='RSB51'></q></dir></style></legend>
                <i id='RSB51'><tr id='RSB51'><dt id='RSB51'><q id='RSB51'><span id='RSB51'><b id='RSB51'><form id='RSB51'><ins id='RSB51'></ins><ul id='RSB51'></ul><sub id='RSB51'></sub></form><legend id='RSB51'></legend><bdo id='RSB51'><pre id='RSB51'><center id='RSB51'></center></pre></bdo></b><th id='RSB51'></th></span></q></dt></tr></i><div id='RSB51'><tfoot id='RSB51'></tfoot><dl id='RSB51'><fieldset id='RSB51'></fieldset></dl></div>
                <tfoot id='RSB51'></tfoot>

                      <bdo id='RSB51'></bdo><ul id='RSB51'></ul>
                        1. <small id='RSB51'></small><noframes id='RSB51'>

                            <tbody id='RSB51'></tbody>