1

如何在单击单个元素时切换音频?

请参阅小提琴http://jsfiddle.net/rabelais/zy2jD/1/

$("#one").toggle(function () {
$('#sound-1').get(0).play();
});
4

1 回答 1

0

这是播放/暂停歌曲:http: //jsfiddle.net/RGJCf/36/

HTML:

<div id="one" class="bar1">
    <i class="play">I tried to tell you</i>
    <i class="stop">I tried to tell you</i>
</div>

CSS:

.stop{
    display:none;
}

JS:

$("#one").click(function () {
    if ($('#sound-1').get(0).paused == false) {
        $('#sound-1').get(0).pause();
        alert('music paused');
    } else {
        $('#sound-1').get(0).play();
        alert('music playing');
    }
    $('i').toggle();
});
于 2013-10-23T14:14:44.293 回答