是否可以通过JavaScript在 img 标签(带像素)中显示图像的任何部分?
Is it possible to show any part of image in img tag (with pixels) via JavaScript?
我会有一个准备好的大图像(例如32x320像素)和定义的起始位置(X,Y,例如0,32)和宽度/高度(例如32,32),并希望脚本显示第二个(32x32像素)部分主图像。
I would have a prepared big image (e.g. 32x320 pixels) and defined starting position (X,Y , e.g. 0,32) and width/height (e.g. 32,32), and would want the script to show second (32x32 pixel) part of main image.
推荐答案您可以使用CSS属性并通过JS更改它们。将图像设置为具有所需大小的元素的背景,并使用背景位置调整其位置,以便可以看到正确的部分。有些人称之为 CSS sprites 。
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.
更多推荐
使用JavaScript获取图像的一部分
发布评论