Programmatically Clip/Cut image using Javascript

后端 未结 8 1874
[愿得一人]
[愿得一人] 2020-12-12 17:57

Are there any documents/tutorials on how to clip or cut a large image so that the user only sees a small portion of this image? Let\'s say the source image is 10 frames of

8条回答
  •  半阙折子戏
    2020-12-12 18:12

    What spriting does is essentially position a absolutely-positioned DIV inside another DIV that has overflow:hidden. You can do the same, all you need to do is resize the outer DIV depending on the size of each frame of the larger image. You can do that in code easily.

    You can just set the inner DIV's style:

    left: (your x-position = 0 or a negative integer * frame width)px
    

    Most JavaScript Frameworks make this quite easy.

提交回复
热议问题