var theight=$(this).find('.tool').height();
var tleft=x-twidth/2;
var ttop=y-theight/2;
if(tleft<0){
tleft=0;
}
if(tleft>width-twidth){
tleft=width-twidth;
}
if(ttop<0){
ttop=0
}
if(ttop>height-theight){
ttop=height-theight;
}
$(this).find('.tool').css({left:tleft,top:ttop});
});
效果如下:

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持软件开发网。










