赞
踩
<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); }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。