在线展示
html:
<div id="box"><ul><li id="li01"><img src="./images/01.jpg" alt=""></li><li id="li02"><img src="./images/02.jpg" alt=""></li><li id="li03"><img src="./images/03.jpg" alt=""></li><li id="li04"><img src="./images/04.jpg" alt=""></li><li id="li05"><img src="./images/05.jpg" alt=""></li></ul>
</div>
css:
<style>*{margin:0; padding: 0;}ul{list-style: none;}#box{width: 360px;height: 70px;border: 1px solid #ccc;padding-top: 360px;margin: 100px auto;overflow: hidden;background: url(./images/01big.jpg) no-repeat;}#box ul{overflow: hidden; /*清除ul里的li标签浮动*/border-top: 1px solid #ccc;}#box li{ float: left;}
</style>
js:
<script>window.onload = function(){function fn(liid,bg){var box = document.getElementById("box");var obj = document.getElementById(liid);obj.onmouseover = function(){box.style.backgroundImage = bg;}}fn("li01","url(./images/01big.jpg)");fn("li02","url(./images/02big.jpg)");fn("li03","url(./images/03big.jpg)");fn("li04","url(./images/04big.jpg)");fn("li05","url(./images/05big.jpg)"); }
</script>