Skip to content
This repository has been archived by the owner on Aug 21, 2019. It is now read-only.

Add "panto" function to allow direct position assignment #29

Open
ogbrandon opened this issue May 27, 2015 · 0 comments
Open

Add "panto" function to allow direct position assignment #29

ogbrandon opened this issue May 27, 2015 · 0 comments

Comments

@ogbrandon
Copy link

I'd rather specify the new position than add or remove pixels from the pan position, which doesn't seem possible to me, so I created the following function to enable this feature.
Feel free to edit and/or integrate.

    /**
      * panto function accessible via direct call (ex : $('#zoomImage').smartZoom('panto', 5, 0);)
      * @param {Number} xPos : a number to move the object current position in X
      * @param {Point} yToAdd : a number to move the object current position in Y
      * @param {Number} duration : move effect duration 700ms by default
      */
    panto : function(xPos, yPos, duration){
        if(xPos == null || yPos == null) // check params
            return;

        if(duration == null) // default pan duration is 700ms
            duration = 700;

        var currentPosition = targetElement.offset();

        var targetRect = getTargetRect();
        var validPosition = getValidTargetElementPosition(xPos, yPos, targetRect.width, targetRect.height); // add the given numbers to the current coordinates and valid the result

        if(validPosition.x != currentPosition.left || validPosition.y != currentPosition.top){
            // stop previous effect before make calculation
            stopAnim(ESmartZoomEvent.PAN);
            moveOnMotion(xPos, yPos, duration);
        }
    },
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant