我通過每一個影像彈出鏈接
<a href="images/capoeira.jpg" data-sound="berimbau" class="fh5co-project-item image-popup to-animate">
<img src="images/berimbau.jpg" alt="Animason groupes" class="img-responsive">
<div class="fh5co-text">
<h1>ANIMA'SON</h1>
<h2>60€/heure/groupe</h2>
<span>Participants: minimum 10, maximum: 20</span>
</div>
<audio id="berimbau-audio" loop="loop" preload="none">
<source src="./sounds/berimbau.ogg" type="audio/ogg">
<source src="./sounds/berimbau.mp3" type="audio/mpeg">
</audio>
</a>
中添加音頻標籤和添加的回調,他莊重,彈出式options.js,使用數據的聲音參數和音頻解決它。 ID
$(文件)。就緒(函數(){VAR soundName; VAR audioElement;
// MagnificPopup
var magnifPopup = function() {
$('.image-popup').magnificPopup({
....
callbacks: {
elementParse: function(item) {
soundName = item.el[0].attributes['data-sound'].value;
audioElement= document.getElementById(soundName + "-audio")
audioElement.load();
},
close: function() {
audioElement.pause();
},
change: function() {
audioElement.play();
}
},