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
Mastering Microdata: A Step-by-Step Guide for HTML5Mastering Microdata: A Step-by-Step Guide for HTML5May 14, 2025 am 12:07 AM

MicrodatainHTML5enhancesSEOanduserexperiencebyprovidingstructureddatatosearchengines.1)Useitemscope,itemtype,anditempropattributestomarkupcontentlikeproductsorevents.2)TestmicrodatawithtoolslikeGoogle'sStructuredDataTestingTool.3)ConsiderusingJSON-LD

What's New in HTML5 Forms? Exploring the New Input TypesWhat's New in HTML5 Forms? Exploring the New Input TypesMay 13, 2025 pm 03:45 PM

HTML5introducesnewinputtypesthatenhanceuserexperience,simplifydevelopment,andimproveaccessibility.1)automaticallyvalidatesemailformat.2)optimizesformobilewithanumerickeypad.3)andsimplifydateandtimeinputs,reducingtheneedforcustomsolutions.

Understanding H5: The Meaning and SignificanceUnderstanding H5: The Meaning and SignificanceMay 11, 2025 am 12:19 AM

H5 is HTML5, the fifth version of HTML. HTML5 improves the expressiveness and interactivity of web pages, introduces new features such as semantic tags, multimedia support, offline storage and Canvas drawing, and promotes the development of Web technology.

H5: Accessibility and Web Standards ComplianceH5: Accessibility and Web Standards ComplianceMay 10, 2025 am 12:21 AM

Accessibility and compliance with network standards are essential to the website. 1) Accessibility ensures that all users have equal access to the website, 2) Network standards follow to improve accessibility and consistency of the website, 3) Accessibility requires the use of semantic HTML, keyboard navigation, color contrast and alternative text, 4) Following these principles is not only a moral and legal requirement, but also amplifying user base.

What is the H5 tag in HTML?What is the H5 tag in HTML?May 09, 2025 am 12:11 AM

The H5 tag in HTML is a fifth-level title that is used to tag smaller titles or sub-titles. 1) The H5 tag helps refine content hierarchy and improve readability and SEO. 2) Combined with CSS, you can customize the style to enhance the visual effect. 3) Use H5 tags reasonably to avoid abuse and ensure the logical content structure.

H5 Code: A Beginner's Guide to Web StructureH5 Code: A Beginner's Guide to Web StructureMay 08, 2025 am 12:15 AM

The methods of building a website in HTML5 include: 1. Use semantic tags to define the web page structure, such as, , etc.; 2. Embed multimedia content, use and tags; 3. Apply advanced functions such as form verification and local storage. Through these steps, you can create a modern web page with clear structure and rich features.

H5 Code Structure: Organizing Content for ReadabilityH5 Code Structure: Organizing Content for ReadabilityMay 07, 2025 am 12:06 AM

A reasonable H5 code structure allows the page to stand out among a lot of content. 1) Use semantic labels such as, etc. to organize content to make the structure clear. 2) Control the rendering effect of pages on different devices through CSS layout such as Flexbox or Grid. 3) Implement responsive design to ensure that the page adapts to different screen sizes.

H5 vs. Older HTML Versions: A ComparisonH5 vs. Older HTML Versions: A ComparisonMay 06, 2025 am 12:09 AM

The main differences between HTML5 (H5) and older versions of HTML include: 1) H5 introduces semantic tags, 2) supports multimedia content, and 3) provides offline storage functions. H5 enhances the functionality and expressiveness of web pages through new tags and APIs, such as and tags, improving user experience and SEO effects, but need to pay attention to compatibility issues.

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

EditPlus Chinese cracked version

EditPlus Chinese cracked version

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