search
HomeWeb Front-endH5 TutorialPlay sound jQuery plug-in based on HTML5 audio element_html5 tutorial skills

1. Some of the previous chatter
When I was in college, it seemed that flash websites were still a little popular, and on any flash website with some content, miscellaneous sound effects were always indispensable. Part of the sound effects is background music that enhances the atmosphere, and the other part is interactive sounds that promote interaction and enhance the experience, such as button presses or "beep" or "beep" sounds when passing by. At that time, there was little sound interaction on web pages far away from Flash. Even if there was, in order to achieve compatibility, one had to rely on controls or interact with Flash (for example, a mentally retarded game I wrote before Implementation of the explosion sound of a neutron bomb hitting its target).

Marx told us that things develop. Girls will one day become young women, and the same goes for technology. For example, Mozilla CEO Gary Kwicks revealed today that Firefox 5 will be officially released on June 22, just 3 months after the release of Firefox 4 – click to view. With the advancement and popularization of HTML5, many effects that could only be achieved with the help of flash in the past can now be easily achieved on web pages. For example, the playback of audio files. This article is just a little trick to easily achieve the effect of playing sounds when elements hover using jQuery. It is based on the HTML5 audio element. Therefore, as far as this article and this plug-in are concerned, IE6~8 is just a mess.

2. Effects, Resources and Usage
Just like a blind date, what the other person looks like is very important, so if you want to get a glimpse of the true face of Lushan, you can click here: Play the sound jQuery Mini Plug-in demo

You can see vertical navigation similar to the following in the demo:

Move the first wave of navigation quickly with the mouse, and there will always be only one voice playing, just like the mother in the heart The call of the mouse; while the mouse moves quickly, a wave of navigation below, multiple sounds crackle like firecrackers, just like the calls of many idols in the heart.

This jQuery plug-in is very simple and very small. It only costs about 30 yuan. You can’t use anti-aircraft guns to fight mosquitoes, so I won’t pack it. If you are interested in the script, you can "right-click - [Target | Link] Save As" following this link: jquery-audioPlay.js

Use
to first call the jQuery library and this effect script file, as shown in the following code :
_fcksavedurl=""http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js">" _fcksavedurl=""http://ajax.googleapis. com/ajax/libs/jquery/1.5.2/jquery.min.js">"

Then, just bind the elements that require the mouse to play sound when it passes by. The method name is: audioPlay(), for example, the following is used in the demo page:

Copy the code
The code is as follows:

$("#nav li").audioPlay({
name: "playOnce",
urlMp3: "/study/media/beep.mp3",
urlOgg: " /study/media/beep.ogg"
});

Obviously, to play sound, it is impossible without an audio file source, so the audio address in the parameter is indispensable. The specific parameters See the table below for relevant instructions:
参数 默认 释义
name “audioPlay” 字符串,用来分组的。用在页面上同时有多组播放元素时。
urlMp3 “” 字符串,此参数必须。指mp3格式的音频文件地址。
urlOgg “” 字符串,此参数必须。指ogg格式的音频文件地址。
clone false 布尔型。同一组元素是否播放同一个声源。

Note: Firefox and Opera browsers support OGG format audio, while webkit core browsers and IE support MP3 format audio.

The sound effects of the upper and lower navigation groups on the demo page apply all the above parameters, and their complete usage is as follows:

Copy code
The code is as follows:

$(function() {
$("#nav li").audioPlay({
name: "playOnce",
urlMp3: "/study/media/beep.mp3",
urlOgg: "/study/media/beep.ogg"
});
$("#nav2 li").audioPlay({
urlMp3: "/study/media/beep.mp3",
urlOgg: "/study/media/beep.ogg",
clone: ​​true
});
});

3. Some nagging at the end
The browsers that currently support the HTML5 audio element are as follows: Firefox 3.5, Chrome 3, Opera 10.5, Safari 4, IE 9, and in this magical country of ours On the Internet, IE6~8 still accounts for most of the country. You may feel that the things in this article are still of little value at present.

However, based on the principle of progressive enhancement and weighing the utility and resource usage, it is not a bad idea to apply this little thing in this article in actual projects. Moreover, with the substantial increase in the installed capacity of Windows 7, the era of IE6 may come to an abrupt end inadvertently. By then, it may not be too late for you to make up for it. This emotion comes from my current landlady, who is 60 or 70 years old. Although she basically knows nothing about computers (she only uses it to read stocks), her computer is a gorgeous Windows 7, and it seems that she can use the Windows 7 system quite well. Quite touching.

Before the big wave of front-end technology arrives, you need to work hard to practice basic skills. Otherwise, when the big wave arrives, you will easily be swallowed up by the oncoming new technology. I personally feel that it is like Japan just after the earthquake, a huge tsunami is coming...
Test code package download
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
H5 and HTML5: Commonly Used Terms in Web DevelopmentH5 and HTML5: Commonly Used Terms in Web DevelopmentApr 13, 2025 am 12:01 AM

H5 and HTML5 refer to the same thing, namely HTML5. HTML5 is the fifth version of HTML, bringing new features such as semantic tags, multimedia support, canvas and graphics, offline storage and local storage, improving the expressiveness and interactivity of web pages.

What Does H5 Refer To? Exploring the ContextWhat Does H5 Refer To? Exploring the ContextApr 12, 2025 am 12:03 AM

H5referstoHTML5,apivotaltechnologyinwebdevelopment.1)HTML5introducesnewelementsandAPIsforrich,dynamicwebapplications.2)Itsupportsmultimediawithoutplugins,enhancinguserexperienceacrossdevices.3)SemanticelementsimprovecontentstructureandSEO.4)H5'srespo

H5: Tools, Frameworks, and Best PracticesH5: Tools, Frameworks, and Best PracticesApr 11, 2025 am 12:11 AM

The tools and frameworks that need to be mastered in H5 development include Vue.js, React and Webpack. 1.Vue.js is suitable for building user interfaces and supports component development. 2.React optimizes page rendering through virtual DOM, suitable for complex applications. 3.Webpack is used for module packaging and optimize resource loading.

The Legacy of HTML5: Understanding H5 in the PresentThe Legacy of HTML5: Understanding H5 in the PresentApr 10, 2025 am 09:28 AM

HTML5hassignificantlytransformedwebdevelopmentbyintroducingsemanticelements,enhancingmultimediasupport,andimprovingperformance.1)ItmadewebsitesmoreaccessibleandSEO-friendlywithsemanticelementslike,,and.2)HTML5introducednativeandtags,eliminatingthenee

H5 Code: Accessibility and Semantic HTMLH5 Code: Accessibility and Semantic HTMLApr 09, 2025 am 12:05 AM

H5 improves web page accessibility and SEO effects through semantic elements and ARIA attributes. 1. Use, etc. to organize the content structure and improve SEO. 2. ARIA attributes such as aria-label enhance accessibility, and assistive technology users can use web pages smoothly.

Is h5 same as HTML5?Is h5 same as HTML5?Apr 08, 2025 am 12:16 AM

"h5" and "HTML5" are the same in most cases, but they may have different meanings in certain specific scenarios. 1. "HTML5" is a W3C-defined standard that contains new tags and APIs. 2. "h5" is usually the abbreviation of HTML5, but in mobile development, it may refer to a framework based on HTML5. Understanding these differences helps to use these terms accurately in your project.

What is the function of H5?What is the function of H5?Apr 07, 2025 am 12:10 AM

H5, or HTML5, is the fifth version of HTML. It provides developers with a stronger tool set, making it easier to create complex web applications. The core functions of H5 include: 1) elements that allow drawing graphics and animations on web pages; 2) semantic tags such as, etc. to make the web page structure clear and conducive to SEO optimization; 3) new APIs such as GeolocationAPI support location-based services; 4) Cross-browser compatibility needs to be ensured through compatibility testing and Polyfill library.

How to do h5 linkHow to do h5 linkApr 06, 2025 pm 12:39 PM

How to create an H5 link? Determine the link target: Get the URL of the H5 page or application. Create HTML anchors: Use the <a> tag to create an anchor and specify the link target URL. Set link properties (optional): Set target, title, and onclick properties as needed. Add to webpage: Add HTML anchor code to the webpage where you want the link to appear.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.