jquery 监听事件on写法解释

摘:https://www.haorooms.com/post/jquery_on_drag

监听事件on写法解释

$(".haorooms").on("click",function(){
    alert("haorooms前端博客")
})

$(".haorooms").on({
        click:function(){
                  alert("我是点击事件")
        },
        mouseover:function(){
            alert("mouseover");
        },
        mouseout:function(){
            alert("out")
        }
    })

最简单的拖拽效果

$(".haorooms_drag").on({
    mousedown: function(e){
                var el=$(this);
                var os = el.offset(); dx = e.pageX-os.left, dy = e.pageY-os.top;
                $(document).on('mousemove.drag', function(e){ el.offset({top: e.pageY-dy, left: e.pageX-dx}); });
            },
   mouseup: function(e){ $(document).off('mousemove.drag'); }

  

猜你喜欢

转载自www.cnblogs.com/liuyj-vv/p/9487327.html
今日推荐