The core is to replace the img src image path with replace to switch between images of different sizes.
The following animation shows the size switch. Click the "big image" button to change the src of the image, load the big image, and click the "small image" button to display the small image.
Replace usage:
I am actually a newbie, but I can't speak to Hai Han.
String. replace (a, B); represents using B to replace the part of the string containing a. For example, the string obj = "welcome to my website! "; Obj. replace (" my "," jb51net "); represents replacing my in the string obj with the string jb51net.
If you are interested, you can use the following code for testing:
Copy codeThe Code is as follows:
Var obj = "welcome to my website! ";
Var newobj = obj. replace ("my", "jb51net's ");
Alert (newobj );
Well, let's talk about this. More things can be learned on the instance page.
Core code:
Copy codeThe Code is as follows:
<Script type = "text/javascript">
$ (Document). ready (function (){
// Convert the image height and width to the em Unit
$ (". Zxx_image"). each (function (){
Var emW = $ (this). width ()/128 + "em ";
Var emH = $ (this). height ()/128 + "em ";
((This).css ("width", emW );
Watermark (this).css ("height", emH)
});
Function srcChg (a, B ){
$ (". Zxx_image"). each (function (){
Var new_src = $ (this). attr ("src"). replace (a, B); // string replacement, change the image path
// Alert (new_src );
$ (This). attr ("src", new_src );
});
}
$ ("# Small_pic"). click (function (){
If ($ (this). hasClass ("on") return;
Else {
$ ("# Big_pic"). removeClass ("on ");
$ (This). addClass ("on ");
$ (". Zxx_image_list" ).css ("font-size", "128px ");
SrcChg ("s256", "s128 ");
Return false; // load IE6 slices after clicking
}
});
$ ("# Big_pic"). click (function (){
If ($ (this). hasClass ("on") return;
Else {
$ ("# Small_pic"). removeClass ("on ");
$ (This). addClass ("on ");
$ (". Zxx_image_list" ).css ("font-size", "256px ");
SrcChg ("s128", "s256 ");
Return false;
}
});
});
</Script>
Packaging jquery-replace-pic-convert.rar