当前位置:   article > 正文

input 鼠标滚动事件_input能触发hover事件吗

input能触发hover事件吗
	<body>
	<div>
        <div>
            <input type="text" id="wheel_1" class="wheelable" value="1" />
        </div>
        
         <div>
            <input type="text" id="wheel_2" class="wheelable" value="1"  />
        </div>
    </div>
</body>

**js部分:**
	$(function() {
		$("#wheel_1").hover(function(){
			EventUtil.addHandler(document,'mousewheel',onWheel);
			EventUtil.addHandler(document,'DOMMouseScroll',onWheel);
		},
		function(){
			EventUtil.removeHandler(document,'mousewheel',onWheel);
			EventUtil.removeHandler(document,'DOMMouseScroll',onWheel);
		});
		
		$("#wheel_2").hover(function(){
			EventUtil.addHandler(document,'mousewheel',onWheel);
			EventUtil.addHandler(document,'DOMMouseScroll',onWheel);
		},
		function(){
			EventUtil.removeHandler(document,'mousewheel',onWheel);
			EventUtil.removeHandler(document,'DOMMouseScroll',onWheel);
		});
	});
	
	
	// WITHOUT Plugin
	var EventUtil = {
	    addHandler: function(element, type, handler){
	        if (element.addEventListener){
	            element.addEventListener(type, handler, false);
	        } else if (element.attachEvent){
	            element.attachEvent("on" + type, handler);
	        } else {
	            element["on" + type] = handler;
	        }
	    },
		
		removeHandler: function(element, type, handler){
	        if (element.removeEventListener){
	            element.removeEventListener(type, handler, false);
	        } else if (element.detachEvent){
	            element.detachEvent("on" + type, handler);
	        } else {
	            element["on" + type] = null;
	        }
	    },
		
		getEvent: function(event) {
	        return event ? event : window.event;
	    },
		
		getTarget: function(event) {
			return event.target || event.srcElement;    
		},
		
		getWheelDelta: function(event) {
	        if (event.wheelDelta){
	            return event.wheelDelta;
	        } else {
	            return -event.detail * 40;
	        }
	    },
		
		preventDefault: function(event) {
	        if (event.preventDefault){
	            event.preventDefault();
	        } else {
	            event.returnValue = false;
	        }
	    }
	    
	};
	
	function onWheel(event) {
	
		event = EventUtil.getEvent(event);
		var curElem = EventUtil.getTarget(event);
		var curVal = parseInt(curElem.value);
		var delta = EventUtil.getWheelDelta(event);
		
		if (delta > 0) {
			curElem.value = curVal + 1;
		} else{ 
			curElem.value = curVal - 1;
		}
		
		EventUtil.preventDefault(event);
		
	}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/223004
推荐阅读
相关标签