javascript - 带有 CSS 推子的 ng-show 不工作

标签 javascript css angularjs

我正在尝试实现找到的第二个解决方案 here让文本在 ng-show 上淡出。我的 HTML 是:

<input ng-focus="hasFocus = true" ng-blur="hasFocus = false"
       type="text" placeholder="Click to fade"/>
<p ng-show="hasFocus" class="fader">Fade me</p>

我的 CSS 是:

.fader.ng-show {
    transition: all linear 500ms;
    opacity: 1;
}

.fader.ng-hide {
    transition: all linear 500ms;
    opacity: 0;
}

我的 Angular 是:

var myApp = angular.module('myApp', []);

JSFiddle 是 here .

最佳答案

我只是做了你正在看的,但我从来没有在 Angular 中使用 ngAnimate 所以我从你的 stackoverflow 问题的引用链接中获取示例代码并添加 fader.ng-hide-removeadd 类现在工作正常,希望这会满足您的条件。

var myApp = angular.module('myApp', ['ngAnimate']);
.fader.ng-hide {
    opacity: 0;
}

.fader.ng-hide-remove,
.fader.ng-hide-add {
  display: block !important;
}

.fader.ng-hide-remove {
  transition: all linear 1000ms;
}

.fader.ng-hide-add {
  transition: all linear 500ms;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.8/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.8/angular-animate.js"></script>
<div ng-app="myApp">
<input ng-focus="hasFocus = true" ng-blur="hasFocus = false" type="text" placeholder="Click to fade"/>
<p ng-show="hasFocus" class="fader">Fade me</p>
</div>

关于javascript - 带有 CSS 推子的 ng-show 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50630733/

相关文章:

javascript - 使用共享 Controller 来处理常见的 html 行为

css - CSS 设计师是否将自己**预先**限制在 CSS 可以处理的布局上?

javascript - 为什么这个 Angular ng-bind 不绑定(bind)到 ng-controller 上?

javascript - 返回值而不是 promise [停止嵌套的延迟 promise ]

javascript - 如何在 Angular 中设置默认选中的单选按钮

javascript - 页面性能 : To load multiple library scripts from CDN or combine and minify those libraries into one download from server?

javascript - 自定义删除 DOM 元素问题

html - 如何使容器覆盖内容的全高?

javascript - 在工具提示中显示表格单元格内容(jsfiddle 在实际站点上不起作用)

javascript - 使用 laravel 编译模板 : Component template requires a root element, 而不仅仅是 vue.js 中的文本时出错