Drag in drag out

Good day,

i want to make an icon that you cant move up or down if its inside its box but if you take it out of its box (but not release it) it goes bigger, if you release it on a place that isn’t one of the two rectangles it goes back to where it was, if you put it on the other rectangle it stays there but you can close it… i might not be so clear but you can do up to what you understand hard to explain=D