Skip to content

Instantly share code, notes, and snippets.

@carambula
Last active December 27, 2015 20:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carambula/7387438 to your computer and use it in GitHub Desktop.
Save carambula/7387438 to your computer and use it in GitHub Desktop.
Example of Framer JS's convertPoint utility in use.
//DEMO: drag the childView inside the box and click the view outside to send it to the relative location of the inner one.
// set up three views, one to hold a child and two that match except for their superViews
parentView = new View({x: 100, y:100, width: 300, height: 300})
childView = new View({x: 20, y: 20, width: 60, height: 40, superView: parentView})
cousinView = new View(childView)
cousinView.superView = parentView.superView
childView.dragger = new ui.Draggable(childView)
cousinView.on("click", function(){
convertedFrame = utils.convertPoint(childView.frame, childView, cousinView.superView)
cousinView.animate({
properties: {x: convertedFrame.x, y: convertedFrame.y},
curve: "ease-in-out",
time: 350
}).on("end", function(){
cousinView.animate({
properties: {x: 20, y: 20},
curve: "spring(30,10,800)"
})
})
})
@koenbok
Copy link

koenbok commented Nov 10, 2013

CousinView is genius. I think others call it a SiblingView :-)

@carambula
Copy link
Author

It's once removed—not under the same parent :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment