0

我有一个示例代码:

<div style="background: url('test.jpg') no-repeat left center; width: 500px; height: 334px;">
   <div id="button-wrapper" style="position: absolute; opacity: 1; z-index: 100;">
   <input type="button" value="submit">    
   </div>
</div>​

和jQuery

jQuery(document).ready(function(){
    jQuery("div[id^=\'button-wrapper\']").parent().mousemove(function(e){
        jQuery("div[id^=\'button-wrapper\']").css({
            top:e.pageY-5,
            left:e.pageX-5
         });
    });
});​

当我鼠标移出框架时出错(div id="button-wrapper")它在超出框架时运行,如何修复它,只在框架中运行?(在这里演示)

4

3 回答 3

1

在代码中定义 mousemove 的包含。

于 2012-11-22T10:15:49.967 回答
1

检查此链接.. 代码更新...

检查此链接

我在那个鼠标 movemnet 上添加了约束

 var a = $(this).height()-15;
         var b = $(this).width()-35;
        if(e.pageY < a&& e. pageX < b)
        {
        $('div[id^="button-wrapper"]').css({
                        top:e.pageY-5,
            left:e.pageX-5
         });
    }
于 2012-11-22T10:29:14.593 回答
0

You need to check if the mouse is being moved outside the parent div. See example at - http://jsfiddle.net/qCbwr/40/.

var _c = $(this);
var _p = _c.position();;

if (_top > (_p.top + _c.height())) _top = _p.top + _c.height();
if (_left > (_p.left + _c.width())) _left = _p.left +_c.width();

You will need to allow for the size of the button if you do not want the control to go outside the div entirely.

于 2012-11-22T10:37:32.197 回答