0

選択したコーナーで要素のサイズを変更するこの関数を作成しました

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 から SMALL への変更 ---> SMALL から BIG への変更

それ以外の場合は、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);
}
4

2 に答える 2