html 点击提示并消失,【已解决】用Bootstrap给html中添加显示后可以消失掉的提示或警告...

折腾:

期间,想要去给用户一个提示,让用户手动点击播放按钮,才能播放音乐。

看到文档中有:

去试试

不过发现:

tooltip貌似更加适合此处场景?

难道是tooltip必须手动点击才可以?

好像是可以代码控制显示和消失的。

bootstrap dismissable tip

bootstrap dismissable alert

期间:

此处,暂时不用自动消失的那种了

也不用显示后,用visibility是show还是hidden -》 否则还占用html的显示空间,不好看

而是:需要显示时,插入显示

用于点击x去自己关闭即可

而插入显示,则需要去:

【总结】

目前用如下代码:

var audioElt = $(".audio_player audio");

console.log("audioElt=%o", audioElt);

var audioObject = audioElt[0];

console.log("audioObject=%o", audioObject);

var playAudioPromise = undefined;

playAudioPromise = audioObject.play();

if (playAudioPromise !== undefined) {

playAudioPromise.then(() => {

// Auto-play started

console.log("Auto paly audio started, playAudioPromise=%o", playAudioPromise);

//for debug

showAudioPlayPreventedNotice();

}).catch(error => {

// Auto-play was prevented

// Show a UI element to let the user manually start playback

// showAudioPlayPreventedNotice();

console.error("play audio promise error=%o", error);

//NotAllowedError: The request is not allowed by the user agent or the platform in the current context, possibly because the user denied permission.

});

}

function showAudioPlayPreventedNotice(){

console.log("showAudioPlayPreventedNotice");

// var prevDisplayValue = $("#audio_play_prevented").css("display");

// console.log("prevDisplayValue=%o", prevDisplayValue);

// $("#audio_play_prevented").css({"display":"block"});

var curAudioPlayPreventedNoticeEltHtml = $("#audio_play_prevented").html();

console.log("curAudioPlayPreventedNoticeEltHtml=%o", curAudioPlayPreventedNoticeEltHtml);

if (curAudioPlayPreventedNoticeEltHtml !== undefined) {

console.log("already exist audio play prevented notice, so not insert again");

} else {

var audioPlayPreventedNoticeHtml = ‘

x Notice: Auto play prevented, please mannually click above play button to play
’;

console.log("audioPlayPreventedNoticeHtml=%o", audioPlayPreventedNoticeHtml);

$(".audio_player").append(audioPlayPreventedNoticeHtml);

}

}

然后,效果是:

0fe8efd3d2f7674848174e1f2ea7a2b8.png

再次想要插入提示,发现已经存在,就不插入提示了:

6c84ffcbc226115b0ae311093fcb3247.png

手动点击关闭后:

429a8766c920bf71795290a30ea10bf1.png

5c4f2617dbc827f92d6900ee1c27252d.png

再去运行,可以继续插入提示:

1b451f52e926813cd4ece62617b8f8e7.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值