我编写了这个函数,通过选定的角调整元素的大小
function RelativeCornerResizer(Elements , StartSize , EndSize , Unit , Left , Top)
{
//var I = StartSize ;
var SSpx = "" , LeftPx="" , TopPx="";
LeftPx = (Left)+Unit;
TopPx = (Top)+Unit;
if(StartSize < EndSize)
{
StartSize+=2;
SSpx = StartSize+Unit;
if(Left!=0) LeftPx = (Left-StartSize)+Unit;
if(Top!=0) TopPx = (Top-StartSize)+Unit;
$(Elements).css({'width': SSpx,'height': SSpx});
$(Elements).css({'left' : LeftPx , 'top' : TopPx});
setTimeout(function(){RelativeCornerResizer(Elements , StartSize , EndSize , Unit , Left , Top)},1);
}
}
现在这只将小元素调整为更大的元素,我想将其概括为从大到小调整大小,所以:
如果我的 StartSize 大于 EndSize ---> BIG to SMALL else ---> SMALL to BIG
一个简单的 if else 可以循环它从 SMALL 到 BIG 到 SMALL 到 BIG [...]
有没有在函数中引入另一个参数的方法?
我修改了 Markus 提出的解决方案,它有效,但我仍然不满意......
function RelativeCornerResizer(Elements , StartSize , EndSize , Unit , Left , Top)
{
var SSpx = "" , LeftPx = "" , TopPx = "", Direction = StartSize < EndSize , Condition ;
LeftPx = (Left) + Unit;
TopPx = (Top) + Unit;
if (Direction)
{ StartSize+=2;
Condition = StartSize < EndSize ;
}
else
{ StartSize-=2;
Condition = StartSize > EndSize ;
}
SSpx = (StartSize) + Unit;
LeftDiff = Direction ? Left - StartSize : Left + StartSize;
TopDiff = Direction ? Top - StartSize : Top + StartSize;
if(Left!=0) LeftPx = (LeftDiff) + Unit;
if(Top!=0) TopPx = (TopDiff) + Unit;
$(Elements).css({'width': SSpx,'height': SSpx, 'left' : LeftPx , 'top' : TopPx});
if(Condition)
setTimeout(function(){RelativeCornerResizer(Elements , StartSize , EndSize , Unit , Left , Top)},1);
}