发布网友 发布时间:2022-04-20 21:45
共1个回答
热心网友 时间:2022-04-22 02:28
//以下代码需要jquery.js
$.fn.floatWith = function(obj,idx){
idx = typeof(idx)!='number' || !idx ? 0 : idx;
var elem = $(obj),offset = elem.offset(),_top = offset.top,_left =offset.left,width = elem.outerWidth(),height=elem.outerHeight();
var floatWidth = this.outerWidth(), floatHeight = this.outerHeight(), cssPos = null;
switch(idx){
case 0: cssPos = {top:_top+height,left:_left}; break;
case 1: cssPos = {top:_top+height,left:_left+width}; break;
case 2: cssPos = {top:_top,left:_left+width}; break;
case 3: cssPos = {top:_top-floatHeight,left:_left+width}; break;
case 4: cssPos = {top:_top-floatHeight,left:_left}; break;
case 5: cssPos = {top:_top-floatHeight,left:_left-floatWidth}; break;
case 6: cssPos = {top:_top,left:_left-floatWidth}; break;
case 7: cssPos = {top:_top+height,left:_left-floatWidth}; break;
default:cssPos = {top:_top+height,left:_left}; break;
}
this.eq(0).css({'position':'absolute'}).css(cssPos).hide().show(200);
return this;
};