Mobile image previewer component
Possible functions:
Gallery preview, pictures can have copywriting, you can slide the screen to preview all pictures, double-click to enlarge/restore, use two fingers to zoom in/out, and move the picture after zooming in; after clicking on the picture, under WeChat (requires access to SDK to add a secure domain name) Open the image previewer that comes with WeChat (similar to the effect when opening a picture in a public account article); open the image previewer that comes with Mobile QQ (the effect of clicking on a picture in an interest tribe article); on other platforms ( And domain names that are not connected to WeChat SDK) open the H5 previewer of the component, which also has an image previewer that is not inferior to WeChat Mobile QQ; how to use it
<script src="//ossweb-img.qq.com/images/js/mobile_gallery/ww_gallery.js"></script>
<script>
var unitMyGallery = new TGI_MobileGallery({
imgArr: document.querySelectorAll(".tuku1 img"),
bigPicAttr: "big-img",
closeWXsdk: 1,
closeQQsdk: 1,
hideInfo: 1,
turnFun: function () {
var n = unitMyGallery.pageX.para.nowPage;
var info = document.querySelectorAll(".tuku1 img")[n].getAttribute("alt");
$(".TMG_txt").html(info);
}
});
</script>
View demo
Component parameters
Value: 0
type of data:
Do you need to turn on the picture preview function that comes with WeChat? (After turning it on, previewing pictures under WeChat will be a full-screen preview)
Value: 0
type of data:
Do you need to turn on the picture preview function that comes with mobile QQ? (After turning it on, previewing the picture under mobile QQ will be a full-screen preview)
Value: all img within body
type of data:
Need to bind the "click to view larger image" function and handle ultra-wide image collection; the default is the img of the entire page;
Value: 0
type of data:
Whether to reconstruct the table so that it can be scrolled; the default is 0;
value:
type of data:
Click stream statistics; suffix comes with xxxxx…tap
Value: big-img
type of data:
Use it when the preview image is inconsistent with the large image, and the image address is inconsistent. Here is a collection of large images, and the input is the attribute name in the image, for example, then it is big-img;
Value: 0
type of data:
Whether the picture information is automatically displayed and hidden; it is a user experience point. The information under the picture will fade in and out within 3 seconds; if set to 1, it will always be displayed;
Value: Custom
type of data:
Do you need to switch left and right buttons? By default, the image preview function that comes with Mobile QQ and WeChat is automatically blocked. The built-in styles of the left and right buttons are: , , and after adding them, they are: ,
Value: 1
type of data:
Previewer mask transparency, value range is 0-1; it is only valid if the built-in image preview function of QQ and WeChat is blocked;
Value: #000
type of data:
Mask color; only masking the built-in picture preview function of QQ and WeChat is effective;
Value: random value
type of data:
If the container ID is not set, it will be randomly generated by default; used when multiple previewers appear on one page and need to be controlled;
Value: tap
type of data:
Click the thumbnail to trigger the preview form, such as click, tap, etc.; the default is tap;
Component methods
turnFun: function() {
var n = unitMyGallery.pageX.para.nowPage;
var info = document.querySelectorAll(".tuku1 img")[n].getAttribute("alt");
$(".TMG_txt").html(info);
}
The function executed by swiping the screen (including the rebound situation if page turning is unsuccessful) will be invalid under the Mobile QQ WeChat platform if the image preview function that comes with Mobile QQ WeChat is not turned off.
After creating a new instance, if the instance is named, you can open the previewer by executing .(num) and locate the corresponding picture; the value range of num is 0 to img.-1;
Case presentation
Example address
Examples of information pages
This is a case for information pages. You can try opening them with QQ, WeChat and browser respectively. The functional points that can be implemented are as follows:
Instructions:
<script src="//ossweb-img.qq.com/images/js/mobile_gallery/ww_gallery.js"></script>
<script>
var unitMyGallery = new TGI_MobileGallery({
imgArr: document.querySelectorAll(".content img"),
needRebuildTable: 1
});
</script>
Cases triggered by other events
Example address
Add a new case. The triggering of the above cases must be based on the pictures in the page. Now add a demo that is triggered by other events; the functions that can be implemented are as follows:
Instructions:
var slidePicGallery = new TGI_MobileGallery({
imgArr: document.querySelectorAll("#slidePic img"),
bigPicAttr: "big-img",
hideInfo: 1,
hottag: "a20160518figma",
btnClass: "btn_slide",
wrapId: "_slide",
opacity: ".3",
coverColor: "blue"
});
$("body").bind("tap", function () {
slidePicGallery.picTapEvent(0);
});