我有一个 Accordion 和上面的音频。我想控制下一个/上一个。去上类。现在单击 $(this)
选项卡切换,但另一个未打开且下一个轨道未播放。;( 当按下一个/上一个控件想要打开下一个 Accordion 并播放轨道时。
这是我的 Accordion JS 代码:
var next = jQuery('.my_music').find('.accordion-toggle');
next.click(function(){
jQuery(this).next().slideToggle('fast');
jQuery(".accordion-content").not(jQuery(this).next()).slideUp('fast');
});
切换下一首轨道:
jQuery('.next_music').click(function(){
// jQuery(next).next().slideToggle('fast');
// cl(this);
jQuery(".accordion-content").not(jQuery(this).next()).slideUp('fast');
});
最佳答案
编辑
(删除了我的第一个答案...测试了这个。有效!;))
$(".next_music").click(function(){
var actualAccordion = $(this).parent().parent().parent('.accordion-content');
console.log("next clicked");
// find the accordion below by getting it's parent's next element (".my_music_wrap").
belowAccordion = actualAccordion.parent().next().children('.accordion-toggle').first();
// Toggle it!
if(belowAccordion.length>0){ // If an accordion is found
actualAccordion.first().slideToggle('fast'); // Toggles actual accordion.
belowAccordion.click() //.slideToggle('fast');
belowAccordion.next().first().children().children().children().children(".audioplayer-playpause").click();
}else{
alert('No other song to play!'); //Will happen on the next button of the fifth song.
}
});
$(".prev_music").click(function(){
var actualAccordion = $(this).parent().parent().parent('.accordion-content');
console.log("prev clicked");
// find the accordion below by getting it's parent's next element (".my_music_wrap").
aboveAccordion = actualAccordion.parent().prev().children('.accordion-toggle').first();
// Toggle it!
if(aboveAccordion.length>0){ // If an accordion is found
actualAccordion.first().slideToggle('fast'); // Toggles actual accordion.
aboveAccordion.click() //.slideToggle('fast');
aboveAccordion.next().first().children().children().children().children(".audioplayer-playpause").click();
}else{
alert('No other song to play!'); //Will happen on the prev button of the first song.
}
});
我重命名了您的 next
var,因为这很令人困惑。
关于javascript - 使用audioplayer.js,想通过使用控件播放下一首轨道,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37597731/