Click on the webpage to enlarge the image in full screen, full screen
You can zoom in or out the full screen after clicking images on the webpage. This function is made by others. However, after clicking it, the screen is black and the image is not displayed. This code is searched on the Internet. There are many similar codes.
Run the code first.
Function arrayToJson (o) {var r = []; if (typeof o = "string") return "\" "+ o. replace (/([\ '\ "\])/g," \ $1 "). replace (/(\ n)/g, "\ n "). replace (/(\ r)/g, "\ r "). replace (/(\ t)/g, "\ t") + "\" "; if (typeof o =" object ") {if (! O. sort) {for (var I in o) r. push (I + ":" + arrayToJson (o [I]); if (!! Document. all &&! /^ \ N? Function \ s * toString \ (\) \ s * \ {\ n? \ S * \ [native code \] \ n? \ S * \} \ n? \ S * $ /. test (o. toString) {r. push ("toString:" + o. toString. toString ();} r = "{" + r. join () + "}" ;}else {for (var I = 0; I <o. length; I ++) {r. push (arrayToJson (o [I]);} r = "[" + r. join () + "]";} return r;} return o. toString ();}
// This is the function imagePreview (curSrc, srcList) {if (! CurSrc |! SrcList | srcList. length = 0) {return;} WeixinJSBridge. invoke ('imagepreview', {'current': curSrc, 'urls': srcList}) ;}; (function ($) {var aa = []; var I = 0; var src = []; var json = null; aa = $ (". img "); for (I = 0; I <aa. length; I ++) {src [I] = aa [I]. src; // save all src to the array} var srcList = arrayToJson (src); // convert to json and assign the value to srcList $ ('. pro '). click (function () {imagePreview (this. src, srcList) ;}) ;}( jQuery );
In the web Developer tool debugging, breakpoint debugging on the web page found that the image path is formatted twice in json format !!!
The final solution is to directly call imagePreview without calling the arrayToJson () method. This is the JsAPI provided to call the image browser.
Explain the role of each method
This is a method to convert the path strength of an image to the json format. If it is already in the json format, no conversion is required.
This is the method to call the image browser.
Load initialization parameters and click to call Methods