Core code:
$ (function () {
$ (". Dvcontent img"). each (function () {
var maxwidth = 520;
if ($ (this). Width () > maxwidth) {
var oldwidth = $ (this). width ();
var oldheight = $ (this). Height ();
var newheight = maxwidth/oldwidth*oldheight;
$ (this). css ({width:maxwidth+ "px", height:newheight+ "px", cursor: "pointer"});
$ (this). attr ("title", "Click to view original image");
$ (this). Click (function () {window.open ($ (this). attr ("src"))};});
If the above code does not execute, you can use the following code:
$ (window). Load (function () {
$ (". Dvcontent img"). each (function () {
var maxwidth =;
if ($ (this). Width () > maxwidth) {
var oldwidth = $ (this). width ();
var oldheight = $ (this). Height ();
var newheight = maxwidth/oldwidth*oldheight;
$ (this). css ({width:maxwidth+ "px", height:newheight+ "px", cursor: "pointer"});
$ (this). attr ("title", "Click to view original image");
$ (this). Click (function () {window.open ($ (this). attr ("src"))};});
There is also a method of using CSS compatible IE6 can make the picture in excess of the specified width automatically proportional reduction, but the wording does not conform to the standard. The code is as follows:
. Cate img{
max-width:600px;
Height:auto;
Width:expression (This.width > 600?) "600px": this.width);
So in order to be compatible with IE and other browsers and meet the standards of the international standard of the image through JS to control the width of the picture, the following use jquery to control the maximum width of the picture display, the main code is as follows:
$ (window). Load (function () {
$ (". Cate img"). each (function () {
var maxwidth =;
if ($ (this). Width () > MaxWidth) {
$ (this). Width (maxwidth);
}
});
The code is very simple, is the Cate style so the maximum width of IMG can only be 600px. each (function () {...}), where each calls the following method for the specified picture collection object. This jquery method enables you to control the maximum width of a picture display in IE6 and above browsers and Chrome and Firefox.