簡體   English   中英

在元素點擊時切換音頻?

[英]Toggle audio on click of element?

單擊單個元素時如何切換音頻?

請參閱小提琴http://jsfiddle.net/rabelais/zy2jD/1/

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

這是播放/暫停歌曲: 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();
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM