【发布时间】:2016-03-10 07:36:05
【问题描述】:
我想在 js 函数中嵌套一个循环的 jQuery 动画函数,但我不知道该怎么做。
我有一个音频文件,在单击 div 时播放(如果再次单击 div 则暂停),同时 div 文本从播放符号变为暂停符号。我想在播放音乐时为另一个 div 设置动画,并在音乐暂停时停止动画。
这是我的音频功能代码:
function play() {
var audio = document.getElementById('whatchaDoin');
if (audio.paused) {
audio.play();
document.getElementById('playButton').innerHTML = '\u2016';
} else {
audio.pause();
document.getElementById('playButton').innerHTML = '\u25BA';
}
}
这是我的动画:
$(document).ready(function() {
function animateBox() {
$('#greenBox').animate({
'margin-top': '20px',
'height': '150px',
'width': '150px'
}, 195).animate({
'margin-top': '30px',
'height': '140px',
'width': '140px'
}, 390, animateBox);
}
animateBox();
});
我似乎找不到在不破坏播放功能的情况下将它们组合在一起的方法。 感谢您能给我的任何帮助!
【问题讨论】:
-
定义“打破播放功能”。另外,你为什么不能把
animateBox()放在你的play函数中?除非我误会了。 -
嗨,马特:我的意思是播放功能停止工作,当我向其中添加 animateBox 功能时——我以几种不同的方式做错了;我不知道如何正确地做到这一点。
标签: javascript jquery jquery-animate