鼠标移上去时,改变li元素的大小、背景色、文字颜色等
代码如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
ul {
margin: 0
padding: 0
}
ul li {
list-style: none
width: 130px
height: 50px
text-align: center
line-height: 50px
font-size: 20px
position: relative
margin-left: 10px
}
div {
width: 150px
height: 500px
border: 1px dashed #000000
text-align: center
}
.active {
background-color: green
color: #fff
}
.show {
width: 2px
height: 20px
position: absolute
left: 10px
top: 15px
background-color: white
}
.li1 {
left: 20px
border-radius: 5px
}
</style>
</head>
<body>
<div id="div1">
<ul>
<li><span></span>雅望天堂1</li>
<li><span></span>雅望天堂2</li>
<li><span></span>雅望天堂3</li>
<li><span></span>雅望天堂4</li>
</ul>
</div>
<script type="text/javascript">
var oLi = document.getElementsByTagName("li")
var oSpan = document.getElementsByTagName("span")
for (var i = 0i <oLi.lengthi++) {
oLi[i].onmouseover = function() {
var sp = this.childNodes[0]
console.log(sp)
for (var i = 0i <oLi.lengthi++) {
oLi[i].setAttribute("class", "")
oSpan[i].setAttribute("class", "")
}
this.setAttribute("class", "active li1")
sp.setAttribute("class", "show")
}
oLi[i].onmouseout = function() {
for (var i = 0i <oLi.lengthi++) {
oLi[i].setAttribute("class", "")
}
}
}
</script>
</body>
</html>
这应该是你要的效果
1.这种一般是后台来进行处理的,如果前端进行处理的话可以用嵌套框架 iframe把需要公用导航独立出来,然后用内联框架引用就可以了。
<iframe src=”你的公用路径.html” width=”100%″ height=”30″ frameborder=”no” border=”0″ marginwidth=”0″ marginheight=”0″ scrolling=”no” allowtransparency=”yes”></iframe>需要准备的材料分别有:电脑、浏览器、html编辑器。
1、首先,打开html编辑器,新建html文件,例如:index.html。
2、在index.html中的<body>标签中,输入html代码:<div style="position: fixedtop: 0right:0">导航</div>。
3、浏览器运行index.html页面,此时div标签由于fixed的位置类型被固定而不随页面滚动。