How to create a slowing scroll effect on a scrollbox?

前端 未结 2 1970
礼貌的吻别
礼貌的吻别 2020-11-28 08:18

I like to create a smooth slowing scroll effect after panning an image in a scrollbox. Just like panning the map in maps.google.com. I\'m not sure what type it is, but exact

2条回答
  •  Happy的楠姐
    2020-11-28 09:03

    In the MouseClickDown event save the X and Y coordinate of mouse cursor in some global variable.

    In the MouseMove event calculate the DeltaX = SavedX - CurrentX and the DeltaY = SavedY - CurrentY values.
    Then scroll your map/image/panel by DeltaX/DeltaY as an absolute value respect your map/image/panel starting position.

    In the MouseClickUp event, use the last calculated DeltaX and DeltaY to set the new starting position of your map/image/panel (essentially leaving it where it is) and reset the SavedX and SavedY values.

    You'll need to check for maximum scrolling position, for border, for what happen when the mouse cursor go outside the application....

提交回复
热议问题