1- <!DOCTYPE html>
2- < html lang ="en ">
3- < head >
4- < meta charset ="UTF-8 ">
5- < title > Title</ title >
6- < script src ="jquery-3.2.0.min.js "> </ script >
7- < style >
8- # url {
9- padding : 5px ;
10- width : 100% ;
11- }
1+ <!DOCTYPE html>
2+ < html lang ="en ">
3+ < head >
4+ < meta charset ="UTF-8 ">
5+ < meta http-equiv ="X-UA-Compatible " content ="IE=edge ">
6+ < meta name ="description " content ="">
7+ < meta name ="keywords " content ="">
8+ < meta name ="viewport "
9+ content ="width=device-width, initial-scale=1 ">
10+ < title > bing wallpaper get from yangpf china</ title >
11+ < link rel ="stylesheet " href ="./css/amazeui.css ">
12+ < style >
13+ .ntn {
14+ height : 5rem ;
15+ padding : 1rem ;
16+ }
17+ .btn1 {
18+ float : left;
19+ width : 30% ;
20+ }
21+ .btn2 {
22+ float : right;
23+ width : 30% ;
24+ }
25+ # txt {
26+ font-size : 1rem ;
27+ text-align : center
28+ }
29+ # b {
30+ text-align : center
31+ }
32+ title {
33+ font-size : 2rem
34+ }
35+ </ style >
36+ </ head >
37+ < body >
38+ < title > bing wallpaper get</ title >
39+ < div class ="wallpaper ">
40+
41+ < figure data-am-widget ="figure "
42+ class ="am am-figure am-figure-default "
43+ data-am-figure ="{ pureview: 'true' } ">
44+ < img id ="img "
45+ />
46+ < figcaption id ="txt " class ="am-figure-capition-btm ">
47+ </ figcaption >
1248
49+ </ figure >
50+ < div class ="ntn ">
51+ < button type ="button " id ="add " class ="btn1 am-btn am-btn-default am-radius am-btn-secondary "> 下一张</ button >
52+ < button type ="button " id ="sub " class ="btn2 am-btn am-btn-default am-radius am-btn-secondary "> 上一张</ button >
53+ </ div >
54+ < p id ="b "> Copyright 2018-2019 chaofeng.xyz yangpf/2018-02-10</ p >
55+ </ div >
56+
57+
58+ </ body >
1359
14- </ style >
15- </ head >
16- < body >
60+ </ html >
61+ < script src ="./js/jquery-3.2.0.min.js "> </ script >
62+ < script src ="./js/amazeui.js "> </ script >
63+ < script >
1764
18- < input type ="text "
19- id ='url '
20- value ="http://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1 ">
21- < input type ="button "
22- id ="load "
23- value ="ajax请求json数据 ">
65+ var test = document . getElementById ( 'img' ) ;
2466
25- < div class ="content ">
26- < img id ="img ">
27- </ div >
67+ test . dataset . rel = "https://www.bing.com/az/hprichbg/rb/BonifacioCorsica_ZH-CN12276076394_1920x1080.jpg" ;
2868
29- </ body >
30- </ html >
31- < script >
32- $ ( function ( ) {
33- $ ( document ) . on ( 'click' , '#load' , function ( ) {
34- var url = $ ( '#url' ) . val ( ) ;
35- $ . get ( 'https://bird.ioliu.cn/v1/?url=' + url , function ( data ) {
3669
37- var imgSrc = 'https://www.bing.com' + data . images [ 0 ] . url
70+ $ ( function ( ) {
71+
72+ $ . get ( "https://bird.ioliu.cn/v1/?url=http://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1" , function ( data ) {
73+ var text = data . images [ 0 ] . copyright ;
74+ var imgSrc = 'https://www.bing.com' + data . images [ 0 ] . url
75+ $ ( '#img' ) . attr ( 'src' , imgSrc )
76+ $ ( '#txt' ) . html ( text )
77+ } , 'json' ) ;
78+ } ) ;
79+ var urlIndex = 0
80+ $ ( "#add" ) . click ( function ( ) {
81+ urlIndex ++ ;
82+ url1 = "http://www.bing.com/HPImageArchive.aspx?format=js&idx=" + urlIndex + "&n=1"
83+ if ( urlIndex > 7 ) {
84+ alert ( "没有图片了" )
85+ urlIndex -- ;
86+ } else {
87+ $ . get ( 'https://bird.ioliu.cn/v1/?url=' + url1 , function ( data ) {
88+
89+ var text = data . images [ 0 ] . copyright ;
90+ var imgSrc = 'https://www.bing.com' + data . images [ 0 ] . url
91+ $ ( '#img' ) . attr ( 'src' , imgSrc )
92+ $ ( '.am-img-loaded' ) . attr ( 'src' , imgSrc )
93+ $ ( '#txt' ) . html ( text )
3894
39- // $('.content').append(imgSrc)
40- $ ( '#img' ) . attr ( 'src' , imgSrc )
41-
42- } , 'json' ) ;
43- } ) ;
44- } ) ;
45- </ script >
95+ } , 'json' ) ;
96+ }
97+ } )
98+ $ ( "#sub" ) . click ( function ( ) {
99+ urlIndex -- ;
100+ url1 = "http://www.bing.com/HPImageArchive.aspx?format=js&idx=" + urlIndex + "&n=1"
101+ if ( urlIndex < - 1 ) {
102+ alert ( "没有图片了" )
103+ urlIndex ++
104+ } else {
105+ $ . get ( 'https://bird.ioliu.cn/v1/?url=' + url1 , function ( data ) {
106+
107+
108+ var text = data . images [ 0 ] . copyright ;
109+ var imgSrc = 'https://www.bing.com' + data . images [ 0 ] . url
110+ $ ( '#img' ) . attr ( 'src' , imgSrc )
111+
112+ $ ( '.am-img-loaded' ) . attr ( 'src' , imgSrc )
113+ $ ( '#txt' ) . html ( text )
114+ } , 'json' ) ;
115+ }
116+ } )
117+
118+
119+ </ script >
0 commit comments