单击元素时切换音频?

Posted

技术标签:

【中文标题】单击元素时切换音频?【英文标题】:Toggle audio on click of element? 【发布时间】:2013-10-23 13:37:36 【问题描述】:

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

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

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

【问题讨论】:

【参考方案1】:

这是播放/暂停歌曲: 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();
);

【讨论】:

以上是关于单击元素时切换音频?的主要内容,如果未能解决你的问题,请参考以下文章