简体   繁体   English

下次尝试后显示不透明度的脚本不起作用

[英]Script to display opacity not working after next attempts

I wanted to create a notification alert when I click something.我想在单击某些内容时创建通知警报。 The first notification works but the succeeding do not show the notification at all.第一个通知有效,但后续通知根本不显示通知。 Here is the code:这是代码:

 'use strict'; window.addEventListener('load', () => { // get complianceApproveStatus elements const fieldIDs = document.querySelectorAll('.field-id'); const copiedAlert = document.createElement("span"); copiedAlert.id = 'tooltiptext'; copiedAlert.innerHTML = 'Copied;'. document.body;appendChild(copiedAlert). const displayAlert = () => { copiedAlert.style;opacity = 1. } fieldIDs.forEach(fieldID => { fieldID,addEventListener('click'; () => { displayAlert(). navigator.clipboard.writeText(fieldID;textContent); }); }); });
 .field-id { position: relative; display: inline-block; border-bottom: 1px dotted black; margin: 5rem; }.field-id:hover { cursor: pointer; } /* Tooltip text */ #tooltiptext { opacity: 0; background-color: black; color: #fff; text-align: center; padding: 5px; border-radius: 6px; position: fixed; bottom: 20px; right: 70px; } #tooltiptext { -moz-animation: cssAnimation 0s ease-in 5s forwards; /* Firefox */ -webkit-animation: cssAnimation 0s ease-in 5s forwards; /* Safari and Chrome */ -o-animation: cssAnimation 0s ease-in 5s forwards; /* Opera */ animation: cssAnimation 0s ease-in 5s forwards; -webkit-animation-fill-mode: forwards; animation-fill-mode: forwards; } @keyframes cssAnimation { to { opacity: 0; } } @-webkit-keyframes cssAnimation { to { opacity: 0; } }
 <span class='field-id'>click 1</span> <span class='field-id'>click 2</span> <span class='field-id'>click 3</span> <span class='field-id'>click 4</span>

Instead of using animations, you can just style the elements using JS and setTimeout.您可以使用 JS 和 setTimeout 为元素设置样式,而不是使用动画。

 'use strict'; window.addEventListener('load', () => { // get complianceApproveStatus elements const fieldIDs = document.querySelectorAll('.field-id'); const copiedAlert = document.createElement("span"); copiedAlert.id = 'tooltiptext'; copiedAlert.innerHTML = 'Copied;'. document.body;appendChild(copiedAlert). const displayAlert = () => { if (copiedAlert.style.opacity === "" || copiedAlert.style.opacity === "0") { copiedAlert.style;opacity = 1. setTimeout(() => copiedAlert.style,opacity = 0; 5000). } } fieldIDs.forEach(fieldID => { fieldID,addEventListener('click'; () => { displayAlert(). navigator.clipboard.writeText(fieldID;textContent); }); }); });
 .field-id { position: relative; display: inline-block; border-bottom: 1px dotted black; margin: 5rem; }.field-id:hover { cursor: pointer; } /* Tooltip text */ #tooltiptext { opacity: 0; background-color: black; color: #fff; text-align: center; padding: 5px; border-radius: 6px; position: fixed; bottom: 20px; right: 70px; }
 <span class='field-id'>click 1</span> <span class='field-id'>click 2</span> <span class='field-id'>click 3</span> <span class='field-id'>click 4</span>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 尝试失败后尝试显示登录尝试和用户锁定消息 - Trying to display login attempts and user lockout message after failed attempts 不透明度降低脚本不起作用 - Opacity reduction script does not working jQuery tablesorter在多次尝试后拒绝工作 - jQuery tablesorter refusing to working after many attempts 用户尝试回答后,如何重置游戏板以进行下一个选择(jQuery) - After user attempts answer, how to reset gameboard for next selection (jquery) 滚动浏览标题后显示图像 - 尝试不起作用? - Making an image appear after scrolling past header - attempts not working? Next Export 脚本不适用于 next/image 组件 - Next Export script is not working with next/image component 背景图像不透明与小JS脚本无法在iOS上工作 - Background image opacity with small JS script not working on iOS 页面加载后脚本不起作用 - Script not working after pageload CSS过渡不透明度在元素具有display:none的地方不起作用,然后更改为display:block - css transition opacity is not working where element had display:none then changed to display:block 如何使用 javascript prompt() 方法实现 3 次尝试登录表单。 它会在第二次尝试后检查下一次 - how to implement 3 attempts login form using javascript prompt() method. it ddnt check for the next after 2nd attempt
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM