Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/469.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 裁剪并调整一组图像的大小,而不会降低质量_Javascript_Jquery_Css - Fatal编程技术网

Javascript 裁剪并调整一组图像的大小,而不会降低质量

Javascript 裁剪并调整一组图像的大小,而不会降低质量,javascript,jquery,css,Javascript,Jquery,Css,我有一个例子: (图片中有3个球) 使用jqueryjquery或css,我希望剪切黄色球,然后更改其大小(宽度和高度)。等等我想要的球 我在帖子中看到了一个方法:。但我正在失去图像质量,无法更改高度或宽度 这是我的代码: function setViewport(img, x, y, width, height) { if (!img) { return; } img.style.left = "-" + x + "px"; img.styl

我有一个例子:

(图片中有3个球)

使用jqueryjquery或css,我希望剪切黄色球,然后更改其大小(宽度和高度)。等等我想要的球

我在帖子中看到了一个方法:。但我正在失去图像质量,无法更改高度或宽度

这是我的代码:

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";
    }
}

从它的声音来看,您希望操纵一个,它允许您在单个图像的片段之间进行选择和交换。您可以自己编写代码,但是有一些插件可以简化jQuery中精灵的管理。但是,使用该工具可以获得更好的性能