javascript - 如何访问函数内部的变量。js中的ES6模块?
问题描述
我正在尝试重构我的代码并将淡出动画提取到 ES6 模块中。但是,我需要在我的主文件中访问一个属性。这怎么可能实现。
我需要能够访问animation
index.js 中的 fadeOut 函数内的变量,以便能够收听动画并继续我的其余代码。
// index.js
import * as Utils from './utilities.js';
Utils.fadeOut(triviaContainerEl, '.trivia-item')
const animation = triviaDiv.animate(keyframes, options)
animation.addEventListener('finish', () => { ... } //Currently, I'm unable to access animation because the fadeOut fn is in another file
// utilities.js
export function fadeOut(parentElement, selector) {
const animatedElement = parentElement.querySelector(selector)
const keyframes = [{
opacity: 1
}, {
opacity: 0
}]
const options = {
duration: 500,
easing: 'ease-out',
delay: 500
}
const animation = animatedElement.animate(keyframes, options)
}
解决方案
推荐阅读
- python - 在 pytz 中查找时区名称是否已弃用
- c# - 如何从另一个窗口调用 MainWindow 方法?
- python - 将 Python 变量写入多个文本文件
- c# - 在自己的构造函数中分配对象值
- java - 仅仅为了分层结构而拥有抽象类是否有意义?
- python - Keras LSTM - 时间序列预测的输入形状
- angular - 如何在 Angular 中推送到表单数组([])
- php - 使用 htaccess 将 http://www.example.com/ 重定向到 https://www.example.com/
- php - 如何使用自定义比较函数计算对象数组的交集?
- java - 具有多对多组合的 Hibernate 复合模式