在隐藏标签中播放声音

编程入门 行业动态 更新时间:2024-10-25 01:33:05
本文介绍了在隐藏标签中播放声音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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="upload.wikimedia/wikipedia/commons/c/c8/Example.ogg">

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

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

更多推荐

在隐藏标签中播放声音

本文发布于:2023-07-11 12:09:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1094005.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:声音   标签

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!