JOIN DEVPPL

It looks like you are new here. If you want to get involved, click on Join below!



[ASK] Hi guys, I cant solve this script . Please help


J

keyboard_arrow_up
0
keyboard_arrow_down


First Post Mark as Spam johnnash
Posts: 2 - Registered: 2013-06-29 20:45:24

sorry for bad english, and here is the script:

// globals
var _player = document.getElementById("player"),
_playlist = document.getElementById("playlist"),
_stop = document.getElementById("stop");

// functions
function playlistItemClick(clickedElement) {
var selected = _playlist.querySelector(".selected");
if (selected) {
selected.classList.remove("selected");
}
clickedElement.classList.add("selected");

_player.src = clickedElement.getAttribute("data-ogg");
_player.play();
}

function playNext() {
var selected = _playlist.querySelector("li.selected");
if (selected && selected.nextSibling) {
playlistItemClick(selected.nextSibling);
}
}

// event listeners
_stop.addEventListener("click", function () {
_player.pause();
});
_player.addEventListener("ended", playNext);
_playlist.addEventListener("click", function (e) {
if (e.target && e.target.nodeName === "LI") {
playlistItemClick(e.target);
}
});

<audio id="player"></audio>

<ul id="playlist"><li data-ogg="Allorge.ogg">Space 1</li><li data-ogg=Allorge.ogg">Space 2</li><li data-ogg="Allorge.ogg">Space Lab</li></ul>

<button id="stop">Stop</button>



it's triggered by click event, but i want this script to run automatically when the element was loaded. I had google it and found nothing but the original script.

thanks.






JOIN DEVPPL

It looks like you are new here. If you want to get involved, click on Join below!




MENU
Advertising