zoukankan      html  css  js  c++  java
  • mousewheel 模拟滚动

                   div{
    			box-sizing:border-box;
    		}
    		.father{
    			500px;
    			height:400px;
    			margin:auto;
    			margin-top: 50px;
    			border: 1px solid red;
    			overflow: hidden;
    			position: relative;
    
    		}
    
    		.child{
    			60%;
    			height: 1210px;
    			border: 1px solid green;
    			margin:auto;
    			position: absolute;
    		 	left:100px;
    		}
    

      

    function load(){
    			window.child=document.getElementById('child');
    			window.father=child.parentNode;
    			father.addEventListener('mousewheel',function(e){
    			// father.addEventListener('scroll',function(e){
    				e.preventDefault();
    				e.stopPropagation();
    				move(e.deltaY*-1);
    			})
    		}
    
    		function move(offset)
    		{
    			var top = child.style.top;
    			if(top==='')
    			{
    				top=0;
    				offset= offset/1 + top/1;
    			}
    			else
    			{
    				top=top.replace('px','');
    				offset= offset/1 + top/1;
    			}
    			var moved=Math.abs(offset) +father.offsetHeight;
    			if(moved>child.offsetHeight && offset<0)
    			{
    				child.style.top = -1*(child.offsetHeight-father.offsetHeight+6) +'px';
    				return;
    			}
    			if(offset>0)
    			{
    				child.style.top='0px';
    				return;
    			}
    			child.style.top=(offset) +'px';
    		}
    

      

    <body onload="load()">
    <div class="father">
    	<div class="child" id="child">
    	</div>
    </div>
    

      

  • 相关阅读:
    ubuntu 12.04 安装 redis
    php 获取中文字符拼音首字母
    js 调整排序
    python 练习
    Configuring Locales
    missing locales
    clean code meaningful names
    ubuntu 12.04 支持中文----完胜版
    why add to http response.responseText
    不通过扩展名,去判断文件类型
  • 原文地址:https://www.cnblogs.com/zyip/p/5625304.html
Copyright © 2011-2022 走看看