0

我的代码是这样工作的:当我单击播放时,“播放”类更改为“暂停”类,但是当我单击暂停时,它不会更改为“播放”类。

第二个问题是如何为音频制作自动循环。

我的代码:

HTML:

<a class="playback">
                <span id="toggle" class="play"></span>
            </a> 
            <audio>
             <source src="<?php bloginfo('template_directory') ?>/venga.ogg" type="audio/ogg" />
                <source src="<?php bloginfo('template_directory') ?>/venga.mp3" type="audio/mpeg" />
                Your browser does not support HTML5 audio.
            </audio>

CSS:

.play {
        background: url('img/play.png') no-repeat;
        width: 32px;
        height: 32px;
        padding: 24px 45px 3px 0px;
        margin: 0 0 0 5px;
    }
    .pause {
        background: url('img/pause.png') no-repeat;
        width: 32px;
        height: 32px;
        padding: 24px 45px 3px 0px;
        margin: 0 0 0 5px;
    }

JS:

<script>
$(function() {
    $(".playback").click(function(e) {
        e.preventDefault();
        var song = $(this).next('audio').get(0);
        if (song.paused)
            song.play();
        else
            song.pause();
    });
});
</script>
 <script type="text/javascript">
$(document).ready(function() {
    $('#toggle').bind("click", function() {
        if ($(this).attr("class") == "play")
            $(this).attr("class", "pause");
        else
            $(this).attr("class", "play");
    });
});
</script>
4

1 回答 1

0

Thank you for giving inspiration for a beginner like me.. the script seems work in my html page, with iOS simulator.

perhaps you include 2 jquery version? i'm not sure where's the problem with your code..

于 2013-04-24T08:41:16.587 回答