【问题标题】:Run some DOM manipulation when an element becomes visible in AngularJS当元素在 AngularJS 中可见时运行一些 DOM 操作
【发布时间】:2023-04-03 00:59:02
【问题描述】:

是否有可能优雅地运行一些代码时某个元素变得可见和另一段代码隐藏时?我想在单页应用中到处应用可滑动的滚动区域,并且只有在元素可见时才有可能。

【问题讨论】:

标签: javascript html css angularjs


【解决方案1】:

Angular 1.1.4 在框架中添加了动画支持。请参阅here 了解更多信息。

您也许可以使用 css3 过渡来实现您的效果,尽管根据您问题中的信息我不确定。或者,您可以在 Javascript 中创建将在 ng-show/ng-hide 上运行的动画:

<div data-ng-hide="hidden == true" data-ng-animate="'myAnimation'">
  ...
</div>
<div data-ng-show="hidden == false" data-ng-animate="'myAnimation'">
  ...
</div>

...

//you can inject stuff!
myModule.animation('myAnimation-show', ['$rootScope', function($rootScope) {
  return { 
    setup : function(element) {
      //this is called before the animation
    },
    start : function(element, done, memo) {
      //this is where the animation is expected to be run
    }
  };
}]);

myModule.animation('myAnimation-hide', ['$rootScope', function($rootScope) {
  return { 
    setup : function(element) {
      //this is called before the animation
    },
    start : function(element, done, memo) {
      //this is where the animation is expected to be run
    }
  };
}]);

编辑:

查看示例here。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-01-27
    • 2023-03-16
    • 2011-07-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-19
    相关资源
    最近更新 更多