GitHub 博客园 Nanakon

【鼠标事件】

位于图片左侧还是右侧

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <style>
        .arrow-right {
            cursor: help;
        }
        .arrow-left {
            cursor: crosshair;
        }
    </style>
</head>
<body>
    <img src="http://pic002.cnblogs.com/images/2012/382256/2012080118323766.gif" width="300" height="225">
    <script src="http://upcdn.b0.upaiyun.com/libs/jquery/jquery-2.0.3.min.js"></script>
    <script>
        var $img = $('img')
        var position = $img.offset().left + $img.width() / 2
        $img.bind('mousemove', function(e) {
            e || (e = window.event)
            if (e.pageX < position) {
                $img[0].className = 'arrow-left'
            } else {
                $img[0].className = 'arrow-right'
            }
        })
    </script>
</body>
</html>

 

posted on 2012-10-17 07:06  jzm17173  阅读(156)  评论(0编辑  收藏  举报

导航

轻音