jQuery:您如何预加载声音? [英] jQuery: How do you preload sound?

查看:127
本文介绍了jQuery:您如何预加载声音?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网站,当您单击按钮时会播放声音.

I have a website that plays sound when you click a button.

这就是我的做法

function PlaySound(soundfile) {
    $('#soundContainer').html("<embed src='/uploads/sounds/" + soundfile + "' hidden=true autostart=true loop=false>");
}

您如何预先预加载声音文件?

How do you preload the sound file beforehand?

谢谢.

推荐答案

只是想在脑海中,您可以向声音文件提出ajax请求,但是在文件被100%加载之前不要显示按钮./p>

just thinking in the top of my head, can you make an ajax request for the sound file, but dont show the button until file is 100% loaded.

$(document).ready(function() {
    $.ajax({
        url: "soundfile.mp3",
        success: function() {
            $("#play_button").show();
        }
    });
});

这篇关于jQuery:您如何预加载声音?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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