日期:2014-05-16 浏览次数:20311 次
<!doctype HTML> <html> <head> <title>scroll</title> <style type="text/css"> #box{width:400px;height:143px;overflow:hidden;position:relative;float:left} ul{position:absolute;left:0;top:0;margin:0px} #slider{width:10px;height:143px;background:#ccc;float:left;position:relative} #slider_btn{position:absolute;top:0;left:0;height:30px;width:10px;background:orange} #wrap{background:orange;padding:10px 0} #wrap a{background:red} #box{background:blue} </style> </head> <body> <div id="wrap"> <a href="">sdsad</a> </div> <div id="box">sdsd</div> <script type="text/javascript"> var $ = function(id){return document.getElementById(id)}; function aa(){ $("box").style.display = "block"; console.log("aa") } function bb(){ $("box").style.display = "none"; console.log("bb") } $("wrap").onmouseover = function(e){ aa(); } $("wrap").onmouseout = function(e){ bb(); } </script> </body> </html>
<!doctype HTML> <html> <head> <title>scroll</title> <style type="text/css"> #box{width:400px;height:143px;overflow:hidden;position:relative;float:left;display:none} ul{position:absolute;left:0;top:0;margin:0px} #slider{width:10px;height:143px;background:#ccc;float:left;position:relative} #slider_btn{position:absolute;top:0;left:0;height:30px;width:10px;background:orange} #wrap{background:orange;padding:10px 0} #wrap a{background:red} #box{background:blue} </style> </head> <body> <div id="wrap"> <a href="">sdsad</a> </div> <div id="box">sdsd</div> <script type="text/javascript"> var $ = function(id){ return document.getElementById(id) }; function aa(){ $("box").style.display = "block"; console.log("aa") } function bb(){ $("box").style.display = "none"; console.log("bb") } function hasChild(elem1, elem2){ var childs = elem1.getElementsByTagName('*'); for(var i = 0, len = childs.length; i < len; i++){ if(elem2 === childs[i]){ return true; } } return false; } $("wrap").onmouseover = function(e){ var event = e || window.event, target = event.target || event.srcElement, relatedTarget = event.relatedTarget || event.fromElement; if(target === this && !hasChild(this,relatedTarget)){ aa(); } } $("wrap").onmouseout = function(e){ var event = e || window.event,