JQ实现图片放大缩小左右旋转(React)

时间:2025-03-29 14:14:29
// 图片缩放 imgToSize(size) { const img = $("#image"); //获取对应的dom const oWidth = img.width(); //取得图片的实际宽度 const oHeight = img.height(); //取得图片的实际高度 img.width(oWidth + size); //设置图片宽度 img.height(oHeight + size / oWidth * oHeight);//设置图片高度 } // 旋转图片 imgRotate(direction) { const img = $("#image"); if (direction == "left") { current = (current - 90) % 360; //特别注意:这里的current是用来记录每次的旋转角度,所以需要定义为全局变量来记录(React可以放入state中,每次执行完后更新一次) } else if (direction == "right") { current = (current + 90) % 360; } img.css('transform', 'rotate(' + current + 'deg)'); }