|
@@ -15,73 +15,104 @@
|
15
|
15
|
}
|
16
|
16
|
|
17
|
17
|
.dv_img {
|
18
|
|
- max-width: 100%;
|
19
|
18
|
height: auto;
|
|
19
|
+ display: block;
|
|
20
|
+ width: 100%;
|
20
|
21
|
}
|
21
|
22
|
</style>
|
22
|
23
|
</head>
|
23
|
24
|
|
24
|
25
|
<body>
|
25
|
|
- <script>
|
26
|
26
|
|
27
|
27
|
|
28
|
|
- const shareImg = `${location.origin}${location.pathname}images/shaer.jpg`
|
|
28
|
+ <img class="dv_img" alt="华侨城集团介绍" src="" data-src="./images/1.jpg" />
|
|
29
|
+ <img class="dv_img" alt="华侨城集团介绍" src="" data-src="./images/2.jpg" />
|
|
30
|
+ <img class="dv_img" alt="华侨城集团介绍" src="" data-src="./images/3.jpg" />
|
29
|
31
|
|
30
|
|
- function request(url, options) {
|
31
|
|
- return fetch(url, options)
|
32
|
|
- .then(response => response.json())
|
33
|
|
- .then(data => {
|
34
|
|
- if (data.code === 1000) return data.data
|
35
|
|
- return Promise.reject(data.message)
|
36
|
|
- })
|
|
32
|
+</body>
|
|
33
|
+<script>
|
|
34
|
+ var imgs = document.querySelectorAll('img');
|
|
35
|
+
|
|
36
|
+ //offsetTop是元素与offsetParent的距离,循环获取直到页面顶部
|
|
37
|
+ function getTop(e) {
|
|
38
|
+ var T = e.offsetTop;
|
|
39
|
+ while (e = e.offsetParent) {
|
|
40
|
+ T += e.offsetTop;
|
37
|
41
|
}
|
|
42
|
+ return T;
|
|
43
|
+ }
|
38
|
44
|
|
39
|
|
- const jsApiList = [
|
40
|
|
- 'updateAppMessageShareData',
|
41
|
|
- 'updateTimelineShareData',
|
42
|
|
- 'onMenuShareTimeline',
|
43
|
|
- 'onMenuShareAppMessage',
|
44
|
|
- 'onMenuShareQQ',
|
45
|
|
- 'onMenuShareWeibo',
|
46
|
|
- 'onMenuShareQZone'
|
47
|
|
- ]
|
48
|
|
-
|
49
|
|
-
|
50
|
|
-
|
51
|
|
- function init(url) {
|
52
|
|
- request(`https://api.h5.njyunzhi.com/mp/jssdk?url=${encodeURIComponent(url)}`).then((res) => {
|
53
|
|
- console.log("🚀 ~ file: index.html ~ line 49 ~ request ~ res", res)
|
54
|
|
- window.wx.config({
|
55
|
|
- debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
|
56
|
|
- appId: res.appId, // 必填,公众号的唯一标识
|
57
|
|
- timestamp: res.timestamp, // 必填,生成签名的时间戳
|
58
|
|
- nonceStr: res.nonceStr, // 必填,生成签名的随机串
|
59
|
|
- signature: res.signature, // 必填,签名
|
60
|
|
- jsApiList // 必填,需要使用的JS接口列表
|
61
|
|
- })
|
62
|
|
- })
|
|
45
|
+ function lazyLoad(imgs) {
|
|
46
|
+ var H = document.documentElement.clientHeight;//获取可视区域高度
|
|
47
|
+ var S = document.documentElement.scrollTop || document.body.scrollTop;
|
|
48
|
+ for (var i = 0; i < imgs.length; i++) {
|
|
49
|
+ if (H + S > getTop(imgs[i])) {
|
|
50
|
+ imgs[i].src = imgs[i].getAttribute('data-src');
|
|
51
|
+ }
|
63
|
52
|
}
|
64
|
|
- function share(opt) {
|
65
|
|
- init(opt.link)
|
66
|
|
- window.wx.ready(function () {
|
67
|
|
- jsApiList.map((apiName) => {
|
68
|
|
- const api = window.wx[apiName]
|
69
|
|
- api({
|
70
|
|
- title: opt.title || '', // 分享标题
|
71
|
|
- link: opt.link || '', // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
|
72
|
|
- imgUrl: opt.imgUrl || '', // 分享图标
|
73
|
|
- desc: opt.desc || ''
|
74
|
|
- })
|
75
|
|
- })
|
|
53
|
+ }
|
|
54
|
+
|
|
55
|
+ window.onload = window.onscroll = function () { //onscroll()在滚动条滚动的时候触发
|
|
56
|
+ lazyLoad(imgs);
|
|
57
|
+ }
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+ const shareImg = `${location.origin}${location.pathname}images/shaer.jpg`
|
|
63
|
+
|
|
64
|
+ function request(url, options) {
|
|
65
|
+ return fetch(url, options)
|
|
66
|
+ .then(response => response.json())
|
|
67
|
+ .then(data => {
|
|
68
|
+ if (data.code === 1000) return data.data
|
|
69
|
+ return Promise.reject(data.message)
|
76
|
70
|
})
|
77
|
|
- }
|
|
71
|
+ }
|
78
|
72
|
|
79
|
|
- share({ title: '华侨城集团介绍', link: window.location.href, imgUrl: shareImg })
|
|
73
|
+ const jsApiList = [
|
|
74
|
+ 'updateAppMessageShareData',
|
|
75
|
+ 'updateTimelineShareData',
|
|
76
|
+ 'onMenuShareTimeline',
|
|
77
|
+ 'onMenuShareAppMessage',
|
|
78
|
+ 'onMenuShareQQ',
|
|
79
|
+ 'onMenuShareWeibo',
|
|
80
|
+ 'onMenuShareQZone'
|
|
81
|
+ ]
|
80
|
82
|
|
81
|
83
|
|
82
|
|
- </script>
|
83
|
84
|
|
84
|
|
- <img class="dv_img" alt="华侨城集团介绍" src="https://h5.njyunzhi.com/images/huaqiaocheng_20211224112744.jpg" />
|
85
|
|
-</body>
|
|
85
|
+ function init(url) {
|
|
86
|
+ request(`https://api.h5.njyunzhi.com/mp/jssdk?url=${encodeURIComponent(url)}`).then((res) => {
|
|
87
|
+ console.log("🚀 ~ file: index.html ~ line 49 ~ request ~ res", res)
|
|
88
|
+ window.wx.config({
|
|
89
|
+ debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
|
|
90
|
+ appId: res.appId, // 必填,公众号的唯一标识
|
|
91
|
+ timestamp: res.timestamp, // 必填,生成签名的时间戳
|
|
92
|
+ nonceStr: res.nonceStr, // 必填,生成签名的随机串
|
|
93
|
+ signature: res.signature, // 必填,签名
|
|
94
|
+ jsApiList // 必填,需要使用的JS接口列表
|
|
95
|
+ })
|
|
96
|
+ })
|
|
97
|
+ }
|
|
98
|
+ function share(opt) {
|
|
99
|
+ init(opt.link)
|
|
100
|
+ window.wx.ready(function () {
|
|
101
|
+ jsApiList.map((apiName) => {
|
|
102
|
+ const api = window.wx[apiName]
|
|
103
|
+ api({
|
|
104
|
+ title: opt.title || '', // 分享标题
|
|
105
|
+ link: opt.link || '', // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
|
|
106
|
+ imgUrl: opt.imgUrl || '', // 分享图标
|
|
107
|
+ desc: opt.desc || ''
|
|
108
|
+ })
|
|
109
|
+ })
|
|
110
|
+ })
|
|
111
|
+ }
|
|
112
|
+
|
|
113
|
+ share({ title: '华侨城集团介绍', link: window.location.href, imgUrl: shareImg })
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+</script>
|
86
|
117
|
|
87
|
118
|
</html>
|