要在按钮上添加发光效果,可以使用CSS的伪类选择器和过渡效果来实现。具体步骤如下:
<button id="myButton">按钮</button>
:hover
来定义鼠标悬停时的样式,例如:#myButton:hover {
box-shadow: 0 0 10px #00ff00; /* 设置发光效果的阴影 */
transition: box-shadow 0.5s; /* 添加过渡效果,使发光效果平滑过渡 */
}
var selectorInput = document.getElementById("selectorInput");
var myButton = document.getElementById("myButton");
selectorInput.addEventListener("change", function() {
if (selectorInput.value === "shiny") {
myButton.classList.add("shiny"); // 添加一个自定义的类名
} else {
myButton.classList.remove("shiny"); // 移除自定义的类名
}
});
.shiny {
box-shadow: 0 0 10px #ff00ff; /* 设置不同的发光颜色 */
transition: box-shadow 0.5s; /* 添加过渡效果,使发光效果平滑过渡 */
}
这样,当选择器输入中的值为"shiny"时,按钮将具有不同的发光效果。
推荐的腾讯云相关产品:腾讯云云服务器(CVM),产品介绍链接地址:https://cloud.tencent.com/product/cvm
领取专属 10元无门槛券
手把手带您无忧上云