css 脚本解释

html-css019

css 脚本解释,第1张

//声明函数startList()

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

<?php

namespace backend\assets

use yii\web\AssetBundle

/**

* @author chan [email protected]>

* @since 2.0

*/

class AppAsset extends AssetBundle

{

public $basePath = '@webroot'

public $baseUrl = '@web'

//全局CSS

public $css = [

'css/animate.css',

'css/style.min.css',

]

[php] view plain copy

//全局JS

public $js = [

'js/jquery-2.1.1.js'

]

[php] view plain copy

//依赖关系

public $depends = [

'yii\web\YiiAsset',

'yii\bootstrap\BootstrapAsset',

]

//定义按需加载JS方法,注意加载顺序在最后

public static function addScript($view, $jsfile) {

$view->registerJsFile($jsfile, [AppAsset::className(), 'depends' =>'api\assets\AppAsset'])

}

//定义按需加载css方法,注意加载顺序在最后

public static function addCss($view, $cssfile) {

$view->registerCssFile($cssfile, [AppAsset::className(), 'depends' =>'api\assets\AppAsset'])

}

}