gpt4 book ai didi

javascript - 如何禁用点击、 Angular 自定义动画?

转载 作者:行者123 更新时间:2023-11-28 17:11:10 25 4
gpt4 key购买 nike

我有 Cordova 应用程序使用 Ionic + Angular(仍然是 1.2.25)

我将我的自定义动画存储在一个 css 文件中:

<link rel="stylesheet" href="css/animations.css">

这个文件有大约20个类

在我的应用程序中,我有设置字段启用/禁用动画。

如何以编程方式禁用 animations.css 的加载?

作为替代方法,我想添加一些根类作为前缀(比如 .animate-flag)到所有动画类,例如:

  .wm-opacity-low-add, .wm-opacity-low-remove {
-webkit-transition: 0.5s linear all;
transition: 0.5s linear all;
}

.wm-opacity-low,
.wm-opacity-low-add.wm-opacity-low-add-active {
opacity: 0.4;
}

.wm-opacity-low-remove.wm-opacity-low-remove-active {
opacity: 1;
}

将成为:

  .animate-flag.wm-opacity-low-add, .animate-flag.wm-opacity-low-remove {
-webkit-transition: 0.5s linear all;
transition: 0.5s linear all;
}

.animate-flag.wm-opacity-low,
.animate-flag.wm-opacity-low-add.wm-opacity-low-add-active {
opacity: 0.4;
}

.animate-flag.wm-opacity-low-remove.wm-opacity-low-remove-active {
opacity: 1;
}

当用户设置动画选项 false - 从所有 DOM 中删除 animate-flag 类,但它看起来有点乱。

是否有其他温和的方法来完成同样的工作?

谢谢,

最佳答案

将所有动画存储在一个 CSS 文件中,您可以尝试像这样“禁用”它:

<head>
<link id="animations-css" rel="stylesheet" href="animations.css">
</head>
<body>
<button id="remove-css">Remove CSS</button>
<button id="add-css">Add CSS</button>
<script>
document.getElementById('remove-css').addEventListener('click', function(){
document.getElementById('animations-css').setAttribute('href', '');
});

document.getElementById('add-css').addEventListener('click', function(){
document.getElementById('animations-css').setAttribute('href', 'animations.css');
});

</script>
</body>

这是一种“肮脏的技巧”,但它应该有效:)

http://plnkr.co/edit/Ut3jLplacMctrrYIO6LP

关于javascript - 如何禁用点击、 Angular 自定义动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29182203/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com