Home > Web Front-end > JS Tutorial > js implements image scaling code compatible with IE and Firefox_javascript skills

js implements image scaling code compatible with IE and Firefox_javascript skills

WBOY
Release: 2016-05-16 15:27:03
Original
977 people have browsed it

The example in this article describes the js implementation of image scaling code that is compatible with IE and Firefox. Share it with everyone for your reference, the details are as follows:

function SetSize(obj, width, height) {
  myImage = new Image();
  myImage.src = obj.src;
  if (myImage.width > 0 && myImage.height > 0) {
    var rate = 1;
    if (myImage.width > width || myImage.height > height) {
      if (width / myImage.width < height / myImage.height) {
        rate = width / myImage.width;
      } else {
        rate = height / myImage.height;
      }
    }
    if (window.navigator.appName == "Microsoft Internet Explorer") {
      obj.style.zoom = rate;
    } else {
      obj.width = myImage.width * rate;
      obj.height = myImage.height * rate;
    }
  }
}

Copy after login

Usage:

Copy code The code is as follows:

This method is applicable to IE, FIREFOX, OPERA, and NETSCAPE tests.

I hope this article will be helpful to everyone in JavaScript programming.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template