通过按钮调用函数后悬停效果消失
Hover effect disappear after calling function through button
我有以下代码只工作,而不是我想要的:
HTML: <div class="horizontal-ribbon">
<div class="list" id="pseudoCheckBoxes">
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
</div>
</div>
<input type="button" id="but" value="next" onclick="check()">
CSS: .horizontal-ribbon {
padding: 8px 8px 8px 8px;
background: #d6dbdf;
}
.list {
position:relative;
}
.list ul {
display:inline-block;
background:#d6dbdf;
margin:0;
padding:0;
border-radius:0px;
color:#ffffff;
}
.list ul li {
cursor: pointer;
cursor: hand;
display:inline-block;
vertical-align:middle;
border-radius: 50%;
width:14px;
height:14px;
padding:0px;
background:#fff;
border: 5px solid #d6dbdf;
color: #ffffff;
text-align:center;
font: 700 13px"Lato", Helvetica, Arial sans-serif;
-webkit-font-smoothing:antialiased;
-moz-osx-font-smoothing: grayscale;
-webkit-transition: background 0.2s ease-out, border-color 0.2s ease-out;
transition: background 0.2s ease-out, border-color 0.2s ease-out;
}
.list ul li:first-child {
margin-left: 20px;
}
.list ul li:last-child {
margin-right: 20px;
}
.list ul li:hover {
background:#1abc9c;
border-color:#1abc9c;
}
JAVASCRIPT: function check() {
element = document.getElementById("pseudoCheckBoxes");
items = element.getElementsByTagName("LI");
items[0].style.backgroundColor = "#1abc9c";
items[0].style.borderColor = "#1abc9c";
setTimeout(function () {
uncheck()
}, 2000);
}
function uncheck() {
element = document.getElementById("pseudoCheckBoxes");
items = element.getElementsByTagName("LI");
items[0].style.backgroundColor = "white";
items[0].style.borderColor = "#d6dbdf";
}
我希望通过按下按钮和将鼠标悬停在<li>
元素上来控制该效果。
悬停效果很好,但在我点击按钮后,悬停效果消失了,我不知道为什么。请帮助我(http://jsfiddle.net/xfpyM/)。
您正在使用CSS悬停应用:hover
效果,并在单击next
按钮后添加内联样式。
你可以试着添加class。
下面是演示
JS
function check(){
element=document.getElementById("pseudoCheckBoxes");
items=element.getElementsByTagName("LI");
items[0].className ="active";
setTimeout(function(){uncheck()}, 2000);
}
function uncheck(){
element=document.getElementById("pseudoCheckBoxes");
items=element.getElementsByTagName("LI");
items[0].className=" ";
}
CSS .list ul li.active,
.list ul li:hover{
background:#1abc9c;
border-color:#1abc9c;
}
您的uncheck
函数有一些错误。不是删除style属性,而是添加不同的样式。所以实际的悬停样式不适用
而不是
function uncheck() {
element = document.getElementById("pseudoCheckBoxes");
items = element.getElementsByTagName("LI");
items[0].style.backgroundColor = "white";
items[0].style.borderColor = "#d6dbdf";
}
像这样使用
function uncheck() {
element = document.getElementById("pseudoCheckBoxes");
items = element.getElementsByTagName("LI");
items[0].removeAttribute("style");
}
相关文章:
- 如何在悬停被移除或消失时应用转换
- 火狐错误 - 悬停时选项消失
- jQuery悬停/隐藏/显示 - 当鼠标悬停在多个图像上时,并非所有文本都会正确消失
- 将鼠标悬停在下拉菜单上时,JQuery 悬停下拉菜单消失
- 如何在没有 CSS 的情况下将鼠标悬停在标题上时使缩略图消失
- 如何单击未完全覆盖背景的对象,并在悬停时消失,同时通过窗口对象退出元素
- D3.js弦图 - 将鼠标悬停在弧上时显示/消失文本
- 背景图像在悬停/鼠标悬停时消失,菜单在IE中不起作用
- 从一个对象悬停到另一个对象,而第二个DOM对象不会立即消失
- 路由:鼠标悬停在ui sref上时可见的参数值在单击时消失
- 弹出以在鼠标悬停时消失
- 使得菜单在悬停在区域之外时保持不变而不会消失
- 在IE 8中选择鼠标悬停时消失的选项
- 为什么第二次我悬停在一个元素上时它就消失了
- 元素消失,直到我悬停在它们上面(Chrome)
- jQuery:将鼠标悬停在一个元素上会使另一个元素褪色,但当鼠标悬停在该元素上时,它会消失
- 使连续的图像只出现在最后一个消失后,而悬停
- 如何点击一个没有完全覆盖背景并在悬停时消失的对象
- 动画文本颜色jQuery CSS悬停消失
- W3总缓存导航悬停消失