在隐藏标签中播放声音 [英] Playing Sound In Hidden Tag

查看:63
本文介绍了在隐藏标签中播放声音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在网页上设置声音.

I am trying to set sound on web page.

我找到了此代码.当 div 可见时,它是工作代码,但我想隐藏起来并工作.在这种情况下,它不起作用,因为它已被 style 属性隐藏.如何使其不可见并同时播放声音?

I found this code. It is working code when the div is visible but I want to be hidden and working. In this case it is not working because it is hidden with style attribute. How to make it not visible and playing sound at the same time ?

<div style="display:none">
   <embed src="sound.mp3"/> 
</div>

推荐答案

我同意以上评论中的观点-这个可以令人讨厌.我们只能希望您为用户提供关闭音乐的选项.

I agree with the sentiment in the comments above — this can be pretty annoying. We can only hope you give the user the option to turn the music off.

但是...

audio { display:none;}

<audio autoplay="true" src="https://upload.wikimedia.org/wikipedia/commons/c/c8/Example.ogg">

css隐藏 audio 元素,然后 autoplay ="true" 自动播放它.

The css hides the audio element, and the autoplay="true" plays it automatically.

这篇关于在隐藏标签中播放声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆