用户首选项,如何使用循环?

时间:2019-12-15 01:56:55

标签: javascript jquery

我对用户首选项有疑问

我希望获得以下效果: 单击“关闭”后-用户看不到代码段 点击“打开”后-用户会看到代码段

当前,我有此代码(来自Internet):

//sweetalert
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@8"></script>

//buttons
const offAnimationsButton = $(".offAnimations"),
onAnimationsButton = $(".onAnimations"),

// Events
offAnimationsButton.on("click", () => {localStorage.setItem('animations', 'off');   Swal.fire({
position: 'mid-end',
type: 'error',
title: 'Example Title - ON',
showConfirmButton: false,
width: 850 
}); removeAnimations();});

onAnimationsButton.on("click", () => {localStorage.removeItem('animations', 'off');     Swal.fire({
position: 'mid-end',
type: 'success',
title: 'Example Title - OFF',
showConfirmButton: false,
timer: 2000,
width: 850 
}); location.reload();});

// Functions removing
const removeAnimations = () => {
$(".animated").removeClass("animated"), $(".fas.fa-cog.fa-spin").removeClass("fa-spin")
},

// After page reload checks     
localStorage.getItem("animations")&&removeAnimations();


//On website
<span class="onAnimations">
<i class="fas fa-circle circleON2"></i>
</span>   

<span class="offAnimations">
<i class="far fa-circle circleOFF2"></i>
</span>

可以正常工作,但网站上的内容不会更改。

在我看来,这里缺少“ if .. else ...”

如何解决我的问题

if (xxx == correct) {
<h1> Lorem Ipsum # 1 </h1>
}


else (xxx == incorrect {
<h1> Lorem Ipsum # 1 </h1>
}

在此先感谢您的帮助:D

0 个答案:

没有答案