startList = function() {
//如果浏览器支持DOM
if (document.all&&document.getElementById) {
//将id为nav的元素赋给变量navRoot,(貌似这个navRoot是全局变量,不然要用var声明)
navRoot = document.getElementById("nav")
//定义一个循环,循环变量i的上限是id为nav的元素的字节点数量,此时navRoot的子节点的集合是数组,i自加1
for (i=0i<navRoot.childNodes.lengthi++) {
//将数组navRoot.childNodes下标索引为i的元素赋给变量node
node = navRoot.childNodes[i]
//如果node的标签的是LI
if (node.nodeName=="LI") {
//当鼠标移动到这个LI标签上时触发以下函数
node.onmouseover=function() {
//这句相当于this.className = this.className + " over",className是其class属性对应的css类名
this.className+=" over"
}
//当鼠标离开该元素时出发以下函数
node.onmouseout=function() {
//此时元素的class属性中的" over"被""替换,""表示空
this.className=this.className.replace(" over", "")
}
}
}
}
}
//当页面读取时,触发startList函数
window.onload=startList
首先给你推荐一种方法:你可以用getElementById("")后边这样用style,这样他会自动提示,这适用于忘记了写法的时候。综合你以上的写法,系统没有getElementsByClassName()这个函数,可以自定义这个方法。style之后的css写法很像java变量的定义,首写字母都是小写,它的第二个单词开始要大写,javascript的变量、函数名等推荐的命名方式也是这样。如果你用setAttribute("style","line-height:"+num+"px")这个和标准css是完全一样的。也就是css怎么写,它就怎么写。保留住动画的最后状态2113,在animation后面加上forwards就可5261以了代码如下:4102
-webkit-animation{animations 1s ease 1 forwards}
注意:动画如果只执行一次,1653通过css无法办到,可以把动画结束时的样式写入一个class中,用js在动画结束时把class赋给这个对象。
扩展资料
CSS animation 与 CSS transition 有何区别
一、指代不同
1、animation :属性是一个简写属性,用于设置六个动画属性。
2、transition:属性是一个简写属性,用于设置四个过渡属性。
二、特点不同
1、animation :animation: name duration timing-function delay iteration-count direction,规定需要绑定到选择器的 keyframe 名称。规定完成动画所花费的时间,以秒或毫秒计。
2、transition:transition: property duration timing-function delay,规定设置过渡效果的 CSS 属性的名称。规定完成过渡效果需要多少秒或毫秒。