JavaScript/jQuery 点击图片 弹出 Layer.open 并避免重复加载 - 优化技巧
"""javascript\nvar imageLoaded = false;\n\n$('img').click(function() {\n if (!imageLoaded) {\n layer.open({\n type: 1,\n content: '<img src="your_image_url">',\n success: function(layero) {\n imageLoaded = true;\n }\n });\n }\n});\n"""\n在上述代码中,imageLoaded 变量初始值为 false,当图片第一次被点击时,会执行 layer.open 方法,并将 imageLoaded 设置为 true,以表示图片已经加载过了。这样,当再次点击图片时,不会再次触发加载操作。
原文地址: https://www.cveoy.top/t/topic/pASb 著作权归作者所有。请勿转载和采集!