This article illustrates the simple implementation of JavaScript, such as scaling down the image of the method. Share to everyone for your reference, specific as follows:
Equal proportions shrink picture
function changeimg (obj,width,height) {
var img = new Image ();
IMG.SRC = document.getElementById (obj.id). src
var ys_w = img.width;
var ys_h = img.height;
if (Ys_w > Width | | ys_h > Height)
{
var scale;
var scale1 = ys_w/width;
var scale2 = ys_h/height;
Alert (scale1+ "," +scale2);
if (Scale1 > Scale2)
{
scale = Scale1;
}
else
{
scale = Scale2;
}
document.getElementById (obj.id). style.width = Ys_w/scale;
document.getElementById (obj.id). style.height = Ys_h/scale;
}
}
More readers interested in JavaScript-related content can view the site topics: "JavaScript switching effects and tips summary", "JavaScript Search Algorithm Skills Summary", "JavaScript animation effects and tips summary", " JavaScript error and debugging skills Summary, JavaScript data structure and algorithm skills summary, JavaScript traversal algorithm and skills summary and JavaScript mathematical calculation usage Summary
I hope this article will help you with JavaScript programming.