这里介绍两种方式:
一:通过css样式中的 :hover实现,代码如下
!DOCTYPE htmlhtml lang=enhead meta charset=UTF-8 titleDocument/title style div{ background:red; width:200px; height:200px; } div:hover{ background:red; width:500px; height:500px; } /style/headbody div变大/div/body/html二:通过javascript方式实现,代码如下
!DOCTYPE htmlhtml lang=enhead meta charset=UTF-8 titleDocument/title style div{ background:red; width:200px; height:200px; } .divs{ background:red; width:500px; height:500px; } /style/headbody div变大/div script // 首先获取div元素 var divs = document.getElementsByTagName('div')[0]; //鼠标移入,将divs的className样式赋给该标签 divs.onmouseover = function () { this.className = divs; } //鼠标移出,将空的className样式赋给该标签 divs.onmouseout = function () { this.className = ; } /script/body/html
取消
评论