简体   繁体   English

Javascript代码中的多个CSS转换

[英]Multiple CSS transitions in Javascript code

My HTML is: 我的HTML是:

<nav id="card-set-menu-nav" ng-style="cardSetMenuNavStyle">
...
</nav>

And my Javascript code using AngularJS is like: 我使用AngularJS的Javascript代码如下:

$scope.openCardSetMenu = function(cardSet) {
    $scope.cardSetMenuNavStyle = {'transition':'0.25s', 'left':'100%')};
    $scope.cardSetMenuNavStyle = {'transition':'0.25s', 'left':'50%')};
};

I want to implement simple side menu by changing $scope.cardSetMenuNavStyle variable. 我想通过更改$ scope.cardSetMenuNavStyle变量来实现简单的侧面菜单。

HTML element card-set-menu-nav will be put at left:100% then be pulled out to left:50% like. HTML元素卡设置菜单导航将放在左边:100%然后拉出左边:50%喜欢。

But it does not work. 但它不起作用。 It does not move at all after the first unfolding... Maybe transitions are ignored because the final result is the same? 在第一次展开后它根本不移动...也许转换被忽略,因为最终的结果是一样的?

How can I apply multiple CSS transitions on an HTML element. 如何在HTML元素上应用多个CSS转换。

Thanks for your help in advance! 感谢您的帮助!

您设定的样式的功能openCardSetMenu内,并确保函数被调用和角码两行删除多余的右括号)..

First of all, remove the extra parenthesis ) at the end of the style declarations. 首先,删除多余的括号)在样式声明的结尾。

Second: do you really need to use AngularJS? 第二:你真的需要使用AngularJS吗? I think you can use CSS transition instead, and "concatenate" transitions with commas and the transition-delay property. 我认为您可以使用CSS transition ,并使用逗号和transition-delay属性“连接”转换。

See CSS3 Transitions in W3Schools for more information about transitions. 有关转换的更多信息,请参阅W3Schools中的CSS3 Transitions

The css transitions property supports transitions for multiple different properties like so: css transitions属性支持多个不同属性的过渡,如下所示:

element {
  transitions: 0.2s left 0.3s color 0.4s 0.8s all
}

Now, if you're setting multiple transitions on one element, I would recommend you look at the animation property and setting custom easings. 现在,如果您在一个元素上设置多个过渡,我建议您查看animation属性并设置自定义宽松。 As for implementing these in AngularJS, I'm not super familiar with it, but it seems like you should use ng-style directive 至于在AngularJS中实现这些,我对它并不是很熟悉,但看起来你应该使用ng-style指令

Hope this was helpful! 希望这有用!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM