How to implement preview effect in JS

亚连
Release: 2018-06-13 15:56:46
Original
2360 people have browsed it

This article mainly introduces JS interactive clicking on pictures in WKWebView to achieve preview effects. Friends in need can refer to

  • Swift 4.0

  • WKWebView

1. Inject js code (emphasis)

func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) { let jsGetImages = "function getImages(){" + "var objs = document.getElementsByTagName(\"img\");" + "var imgScr = '';" + "for(var i=0;i
        
Copy after login

2. Use SKPhotoBrowser framework to implement image preview function

func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) { let requestString = navigationAction.request.url?.absoluteString print(requestString!) if (requestString?.hasPrefix("image-preview"))!{ let imgUrl = NSString.init(string: requestString!).substring(from: "image-preview:".count ) let index = imgUrlArray.index(of: imgUrl) let browser = SKPhotoBrowser(photos: images) browser.initializePageIndex(index) present(browser, animated: true, completion: {}) } decisionHandler(.allow) //一定要加上这句话 }
Copy after login

The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

How to calculate polygon centroid in JavaScript

About the use of custom form controls in Angular19

How to use switch selector in WeChat applet

Detailed interpretation of Angular error 404 issues

How to use the slider component in the WeChat applet

How to remember the password to the cookie in vue

AngularJS important version update

Instructions for using button components in WeChat mini programs

The above is the detailed content of How to implement preview effect in JS. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!