导航悬停在浅色背景上
Onhover of Navigation change to light color background
我正在为我的网站做一个功能,我想要一个相同的功能。
详细:当我将鼠标悬停在导航上时,我想使背景发光。
如果需要其他任何内容,请告诉我。
我希望我能理解你的问题。请参阅以下示例:
$(document).ready(function() {
$("ul li").mouseover(function () {
$(this).addClass('light-bg', 1000);
$('body').addClass('new-body-bg', 1000);
});
$("ul li").mouseleave(function () {
$(this).removeClass('light-bg', 1000);
$('body').removeClass('new-body-bg', 1000);
}); });
ul {
background-color: #ddd; /* Choose the color of your choice */
height: 40px;
}
li {
display: inline-block;
font-size: 18px;
padding: 10px;
line-height: 20px;
text-align: center;
margin-right: 15px;
}
.light-bg {
background-color: #fff; /* Choose the color of your choice */
line-height: 20px;
}
.new-body-bg {
background-color: #ccc; /* Choose the color of your choice */
position: relative;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul>
<li><a href="#"> One </a></li>
<li><a href="#"> Two </a></li>
<li><a href="#">Three </a></li>
<li><a href="#"> Four</a></li>
</ul>
它在 JsFiddle 上完美运行
参见:http://jsfiddle.net/snlacks/tekokmke/1/
不使用jQuery,
- 你想找到你想要这样做的所有元素
- 然后你想遍历它们
- 您将为每个侦听器应用两个侦听器,一个用于进入,一个用于离开。
.js:
var mes = document.querySelectorAll(".me");
function changeIn(){
document.body.style.backgroundColor = "lightgray";
}
function changeOut(){
document.body.style.backgroundColor = "darkgray";
}
for(i = 0; i < mes.length; i++){
mes[i].onmouseenter = changeIn;
mes[i].onmouseleave = changeOut;
}
相关文章:
- 导航菜单-悬停时的背景行为怪异
- 鼠标悬停时如何居中放大背景图像
- DT数据表背景颜色为黑色,但仍有悬停和选择颜色
- "Ken Burns效应”;悬停背景图像
- 如何动画删除悬停后的背景
- 更改鼠标悬停时映射图像热点的背景
- 悬停在链接上时不断更改背景图像
- 如何获取元素:使用javascript和CORS悬停背景
- 文本悬停效果加上背景更改
- 当我悬停按钮时,更改按钮的背景
- 文本的实时预览使链接在悬停时不会更改背景颜色
- 鼠标悬停时随机更改背景图像
- 悬停时缩放背景图像
- 如何在Javascript中悬停,将背景颜色更改为特定的类
- 在背景悬停时更改光标
- Facebook的哪些部分;s界面代码负责在悬停时更改徽标的背景颜色
- 悬停时的CSS背景
- 悬停时更改正文背景
- 更改元素父元素的背景颜色时停止在
上闪烁鼠标悬停?jQuery/JS. - 将鼠标悬停在子级上并更改父级背景颜色