视频链接: 视频
代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>滚轮</title>
<style type="text/css">
#box1{
width: 100px;
height: 100px;
background-color: #6495ED;
}
</style>
<script type="text/javascript">
window.onload=function(){
var box1=document.getElementById("box1");
box1.onmousewheel=function(event){
event=event||window.event;
if(event.wheelDelta>0 ||event.detail<0){
box1.style.height=box1.clientHeight-10+"px";
}else{
box1.style.height=box1.clientHeight+10+"px";
}
event.preventDefault&&event.preventDefault();
return false;
};
bind(box1,"DOMMouseScroll",box1.onmousewheel);
}
function bind(obj,eventStr,callback){
if( obj.addEventListener){
obj.addEventListener(eventStr,callback,false);
}else{
obj.attachedEvent("on"+eventStr,function(){
callback.call(obj);
});
}
}
</script>
</head>
<body>
<div id="box1"></div>
</body>
</html>
|