I have a following example situation:
(3 balls inside a picture)
With jquery jquery or css, I want to cut the yellow ball and then change its size (width and height). And so on for the balls I want
I was shown a method in a post: Programmatically Clip/Cut image using Javascript . But I'm losing image quality and can't change the height or width
There is my code:
function setViewport(img, x, y, width, height) {
if (!img) {
return;
}
img.style.left = "-" + x + "px";
img.style.top = "-" + y + "px";
if (width !== undefined) {
img.parentNode.style.width = width + "px";
img.parentNode.style.height = height + "px";
}
}
From the sound of it, you want to manipulate an image sprite , which allows you to select and swap between segments of a single image. You can code your own but there are plugins like jquery-sprite to simplify managing sprites in jQuery. You'll get better performance using CSS sprites , however.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.