3
나는) (단지 JQuery와 플레이 (함께 MP3 재생) 및 일시 정지, 또 다른 질문에서 약간의 코드를 발견 "재생"링크의 rel 속성. 이제 더 많은 오디오 링크를 추가하고 rel 속성에 상대적인 소스를 만들고 싶습니다. 최소한의 놀이() 및 일시 정지() 오디오 솔루션
나는var source = $(this).attr('rel');
을 시도하고도 .find()와 .each(),하지만 아무것도 지금까지 일했다. 두 번째 오디오 링크가있는
jsfiddle을 설정했습니다. 첫 번째 오디오 파일 만 재생됩니다. (바이올린은 클라이언트가 자신의 사이트에서 사용하는 외부 스크립트에 연결됩니다. jquery 1.4.3 만로드되지만 어쨌든 가능할 것 같습니다. 오디오 플레이어 플러그인을 사용하지 않으려 고합니다. 최소의 솔루션입니다.)
도움을 주시면 매우 감사하겠습니다! 바이올린을
$(document).ready(function() {
// For each container div
$(".container").each(function() {
// Create the HTML5 <audio> tag
var audioElement = document.createElement('audio');
// Find the play/pause buttons
var $play = $(this).find(".play");
var $pause = $(this).find(".pause");
// Load the source from the play button
var source = $play.attr('rel');
audioElement.setAttribute('src', source);
$.get();
// Play the sound when loaded
audioElement.addEventListener("load", function() {
audioElement.play();
}, true);
// When the user clicks on the play button, play the audio
$play.click(function() {
audioElement.play();
});
// When the user clicks on the pause button, pause it
$pause.click(function() {
audioElement.pause();
});
});
});
을 그리고 업데이트 :
이 완벽하게 작동합니다! 고마워요 :-) – Alani
@Alani 아무 문제 없어요, 그것이 당신을 위해 작동한다면 답변으로 표시하십시오 :) – CodingIntrigue