gpt4 book ai didi

javascript - 禁用和重新启用功能、静音和取消静音

转载 作者:行者123 更新时间:2023-12-03 03:53:18 24 4
gpt4 key购买 nike

您好,我正在尝试通过单击一个按钮来禁用某个功能,然后在单击另一个按钮后再次启用它我已尝试取消绑定(bind),但我没有得到任何结果对我如何解决这个问题有什么建议吗?

代码:

<a href="#" class="MuteOn">Mute</a>
<a href="#" class="MuteOff">Unmute</a>

$('.MuteOn').on('click tap touch', function() {
//Disable soundListen function
});

$('.MuteOff').on('click tap touch', function() {
//Enable soundListen function
});

//

setInterval(function soundListen() {
if ($("body").hasClass("fp-viewing-1")) {
audio1.play();

} else {
audio1.pause();
audio1.currentTime = 0;
}

if ($("body").hasClass("fp-viewing-2")) {
audio2.play();
} else {
audio2.pause();
audio2.currentTime = 0;
}

if ($("body").hasClass("fp-viewing-3")) {
audio3.play();
} else {
audio3.pause();
audio3.currentTime = 0;
}
}, 100);

预先感谢您的任何建议。

最佳答案

好吧,我是这样理解的:- 在第一页上,用户可以单击静音/取消静音按钮,并且在浏览所有其他页面/幻灯片时应保存该按钮。

然后这是一个代码:

<!doctype>
<html lang="en">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title></title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<button id="mute">Mute</button>
<button id="unmute">Unmute</button>
<button id="reloadPage">Reload Page</button>
<script type="text/javascript">

//get variable from local variables or set to false(you can change it to TRUE if you like to mute on page load) by default
var isMuted = localStorage.getItem("IsMuted")||false;

//mute button onclick method
$(document).on('click','#mute',function(e){
isMuted = true;
//save to local variables
localStorage.setItem("IsMuted", isMuted);
});

//unmute button onclick method
$(document).on('click','#unmute',function(e){
isMuted = false;
//save to local variables
localStorage.setItem("IsMuted", isMuted);
});

//reload page. also you can use F5 or Ctrl+F5
$(document).on('click','#reloadPage',function(e){
location.reload();
});

$(document).ready(function(){
alert("IsMuted = "+isMuted);

//you can encapsulate this into separate function and bind to show-next-slide button
if(isMuted)
{
return;
}
else
{
//get clip id by class name or another suitable method
PlayMyCoolMusic(clipId);
}
});



function PlayMyCoolMusic(clipId)
{
//your audio player logic here

}
</script>
</body>
</html>

使用此功能,即使页面已重新加载,您也可以保存静音/取消静音状态。

关于javascript - 禁用和重新启用功能、静音和取消静音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45080330/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com