getting part of an image with JavaScript

后端 未结 2 1448
悲哀的现实
悲哀的现实 2020-12-19 07:04

Is it possible to show any part of image in img tag (with pixels) via JavaScript?

I would have a prepared big image (e.g. 32x320 pixels) and defined sta

相关标签:
2条回答
  • 2020-12-19 07:22

    For the sake of giving you multiple options, you could always use an HTML5 canvas and redraw the image as necessary. You can find a nice tutorial about how to do this here : https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Canvas_tutorial/Using_images The CSS sprite method would be preferable nonetheless as IE doesn't support canvas yet.

    0 讨论(0)
  • 2020-12-19 07:28

    You could use CSS properties for this and change them via JS. Set the image as a background for an element with your desired size and adjust its position with background-position so that the correct part of it is visible. Some people call it CSS sprites.

    0 讨论(0)
提交回复
热议问题