JQ的自定义事件操作

48 阅读1分钟

设置一个滚轮事件放到缩小图片

<body>
<img src="1.jpg" id="img1">
</body>
<script>
$(function(){  
    $('#img1').on('zoomIn',function(){  //缩小       
        $(this).css('width',200);      
    });

    $('#img1').on('zoomOut',function(){  //放大      
        $(this).css('width',700);      
    });

    $('#img1').on('DOMMouseScroll',function(ev){

        if(ev.originalEvent.detail > 0){
            $(this).trigger('zoomIn');
        }
        else{
            $(this).trigger('zoomOut');
        }       
    }); 
});
</script>