خرید بک لینک
Hi there folks,

Unfortunately I can't code in JS just now, it's something I would love to and shall learn I'm sure but I hope it's not considered too 'cheaty' asking for some help here on a current project :)

I've got a slideshow up on a site with some simple code I found online:

Code:

    <div id="cartoon_box">
   
      <button class="w3-button w3-display-left" onclick="plusDivs(-1)">❮</button>
      <button class="w3-button w3-display-right" onclick="plusDivs(1)">❯</button>
         
        <img class="mySlides" src="gfx/cartoon_dt/01.jpg">
        <img class="mySlides" src="gfx/cartoon_dt/02.jpg">
        <img class="mySlides" src="gfx/cartoon_dt/03.jpg">
        <img class="mySlides" src="gfx/cartoon_dt/04.jpg">
        <img class="mySlides" src="gfx/cartoon_dt/05.jpg">
        <img class="mySlides" src="gfx/cartoon_dt/06.jpg">
        <img class="mySlides" src="gfx/cartoon_dt/07.jpg">
        <img class="mySlides" src="gfx/cartoon_dt/08.jpg">
        <img class="mySlides" src="gfx/cartoon_dt/09.jpg">
        <img class="mySlides" src="gfx/cartoon_dt/10.jpg">
        <img class="mySlides" src="gfx/cartoon_dt/11.jpg">
        <img class="mySlides" src="gfx/cartoon_dt/12.jpg">
        <img class="mySlides" src="gfx/cartoon_dt/13.jpg">
        <img class="mySlides" src="gfx/cartoon_dt/14.jpg">

    </div>

<script>
var slideIndex = 1;
showDivs(slideIndex);

function plusDivs(n) {
    showDivs(slideIndex += n);
}

function showDivs(n) {
    var i;
    var x = document.getElementsByClassName("mySlides");
    if (n > x.length) {slideIndex = 1}
    if (n < 1) {slideIndex = x.length} ;
    for (i = 0; i < x.length; i++) {
        x[i].style.display = "none";
    }
    x[slideIndex-1].style.display = "block";
}
</script>

This works great but I'd really like to have an mp3 sound linked to each slide so that the appropriate mp3 is played on the pressing of the forward/backward buttons (1.mp3 for slide 1, 2.mp3 for slide 2 etc)

So I found this code snippet for playing sounds at the onclick event:

Code:

<script>
    function PlaySound(melody) {
        alert("On Press of "+melody);
        var path = "path\to\melody\"
        var snd = new Audio(path + melody + ".mp3");
        snd.play();
    }
</script>

<button onclick="PlaySound('melody1')"> button1</button>
<button onclick="PlaySound('melody2')"> button2</button>

But knowing next to nothing about JS just now, I wondered if anyone would be kind enough to help me combine the 2?

Cheers

برچسب: نویسنده: آیلین رضوانی تاريخ: شنبه 18 آذر 1396 ساعت: 4:01

صفحه بندی