-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
689 lines (671 loc) · 15.5 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>今日新闻</title>
</head>
<link rel="stylesheet" href="./css/bootstrap.min.css">
<link rel="stylesheet" href="./css/reset.css">
<link rel="icon" href="static/news.png" type="image/x-icon" />
<link rel="shortcut icon" href="static/news.png" type="image/x-icon"/>
<script src="./js/ajax.js"></script>
<style>
@keyframes fade {
to {
opacity: 0;
}
}
body {
height: auto;
background-color: #f3f3f3;
}
a:hover {
text-decoration: none;
}
h1 {
letter-spacing: 13px;
text-align: center;
}
.container {
padding-top: 20px;
}
.search {
position: relative;
width: 100%;
height: 30px;
margin-bottom: 10px;
}
.search .res {
position: absolute;
right: 0;
z-index: 2;
height: 100%;
width: 410px;
}
.search input {
float: right;
width: 410px;
height: 30px;
margin-top: 5px;
text-indent: 1em;
outline: none;
border: none;
}
.search .newlist {
margin-top: 5px;
z-index: 2;
background-color: #fff;
}
.newlist .list{
height: 40px;
width: 100%;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
line-height: 40px;
}
.newlist .list:hover {
background-color: #64a1d5;
}
.list:hover {
background-color: #64da;
}
/*轮播图*/
.carousel {
position: relative;
}
.carousel .wrap{
height: 180px;
background-color: #5158;
}
.wrap .cont{
display: none;
width: 100%;
height: 100%;
}
.cont.active {
display: block;
}
.cont span {
position: absolute;
width: 100%;
padding: 0 5px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
z-index: 2;
color: #fff;
}
.cont img {
width: 100%;
height: 100%;
}
.ul {
display: none;
position: absolute;
bottom: 5px;
width: 100%;
text-align: center;
}
.ul li {
display: inline-block;
width: 10px;
height: 10px;
margin: 0 4px;
cursor: pointer;
border-radius: 50%;
background-color: #fff;
}
.ul li.active {
background-color: #00f;
}
.carousel:hover .ul,
.carousel:hover .lr {
display: inline-block;
}
.lr {
display: none;
position: absolute;
top: 50%;
width: 100%;
margin-top: -15px;
}
.left,
.right {
width: 30px;
height: 30px;
cursor: pointer;
background-size: 100%;
}
.left {
float: left;
background-image: url(static/left.png);
}
.right {
float: right;
background-image: url(static/right.png);
}
/*头部样式*/
.header {
margin-bottom: 10px;
font-size: 1.3em;
box-shadow: 0 5px 5px rgba(0, 0, 0, .3);
border-bottom: 1px solid black;
border-radius: 6px;
background: linear-gradient(to left,
#ce5757,
#c738c7,
#13cc66
);
}
.header li {
float: left;
margin: 0 5px;
color: #fff;
cursor: pointer;
}
.header li.active {
color: #762;
text-decoration: underline;
}
.wrapper {
margin-bottom: 30px;
}
/*每列样式*/
.column {
min-height: 250px;
min-width: 280px;
max-width: 380px;
height: 300px;
margin: 10px 0px;
overflow: hidden;
}
.column .title {
height: 15%;
border-top-left-radius: 10px;
border-top-right-radius: 10px;
background-color: #fff;
border-bottom: 1px solid #ce5757;
}
.column h2{
height: 100%;
max-height: 100%;
padding: 10px 5px;
font-size: 20px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.column .img {
width: 100%;
height: 85%;
max-height: 85%;
overflow: hidden;
}
.column .img img{
width: 100%;
height: 100%;
}
.column:hover img{
transform: scale(1.1);
transition: transform .8s;
}
.column .detail {
display: inline-block;
width: 100%;
height: 100%;
cursor: pointer;
}
.action li {
float: right;
margin: 0 10px;
}
.action li:first-child {
float: left;
}
.action li:first-child span {
color: #f00;
font-style: italic;
}
.footer {
text-align: center;
font-size: 1em;
margin: 30px 0;
}
.about {
padding: 10px;
text-align: center;
background-color: #e1e1e1;
}
.hot {
padding: 0;
margin: 0;
}
.hot li {
height: 30px;
line-height: 30px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
border-bottom: 1px solid #e1e1e1;
}
.hot li span {
margin-right: 10px;
}
.hot li:nth-child(1){
color: #f00;
}
.hot li:nth-child(2){
color: #F30;
}
.hot li:nth-child(3){
color: #D42F;
}
.hot li:nth-child(4){
color: #D92F;
}
.hot li:nth-child(5){
color: #C93F;
}
</style>
<body>
<div class="container">
<header>
<h1>今日新闻</h1>
<div class="search row">
<div class="res">
<input type="text" class="searchIn form-control" autocomplete="off" placeholder="搜索新闻">
<ul class="newlist">
</ul>
</div>
</div>
</header>
<div class="row">
<nav>
<ul class="header col-md-12 col-sm-12 col-xs-12">
<li class="active">
全部
</li>
<li>
国内
</li>
<li>
国际
</li>
<li>
科技
</li>
<li>
军事
</li>
<li>
财经
</li>
<li>
娱乐
</li>
<li>
体育
</li>
<li>
互联网
</li>
<li>
汽车
</li>
<li>
房产
</li>
</ul>
</nav>
<ul class="action">
<li>欢迎您 <span class="username">新用户</span></li>
<li>
<a href="./html/regist.html">注册</a>
</li>
<li>
<a href="./html/login.html">登录</a>
</li>
</ul>
</div>
<article>
<div class="row">
<div class="col-lg-6">
<div class="carousel">
<ul class="wrap">
</ul>
<ul class="ul">
</ul>
<div class="lr">
<span class="left"></span>
<span class="right"></span>
</div>
</div>
</div>
<div class="col-lg-6">
<aside>
<h2>热点新闻</h2>
<ol class="hot">
</ol>
</aside>
</div>
</div>
<div class="wrapper row">
正在加载数据......
</div>
</article>
<div class="footer">没有数据了</div>
</div>
<footer>
<div class="about">
<p class="about-p-top">
<span><a href="##">关于本站</a></span>
<span><a href="##">合作伙伴</a></span>
<span><a href="##">营销中心</a></span>
<span><a href="##">廉政举报</a></span>
<span><a href="##">联系客服</a></span>
<span><a href="##">开放平台</a></span>
<span><a href="##">诚征英才</a></span>
<span><a href="##">联系我们</a></span>
<span><a href="##">网站地图</a></span>
<span><a href="##">法律声明及隐私权政策</a></span>
<span><a href="##">知识产权</a></span>
<span><b>|</b></span>
<span>
<em>© 2019-现在 xmw.com 版权所有</em>
</span>
</p>
<p class="about-p-center">
<span><a href="##">网络文化经营许可证:浙网文[2019]0268-027号</a></span>
<span><b>|</b></span>
<span><a href="##">增值电信业务经营许可证:浙B2-20080224</a></span>
<span><b>|</b></span>
<span>
<em>互联网违法和不良信息举报电话:0571-81683755 blxxjb@xmw-inc.com</em>
</span>
</p>
<p class="about-p-bot">
<span class="pic"></span>
<span><a href="##">浙公网安备 33010002000078号</a></span>
<span><b>|</b></span>
<span>
<em>(浙)网械平台备字[2018]第00004号</em>
</span>
<span><b>|</b></span>
<span><a href="##">出版物网络交易平台服务经营备案证:新出发浙备字第002号</a></span>
<span><b>|</b></span>
</p>
</div>
</footer>
<script>
let data;
let res = [];
let row = document.getElementsByClassName("wrapper")[0];
let frage = document.createDocumentFragment();
let aArr = document.querySelectorAll(".header li");
let username = document.querySelectorAll(".username");
let searchIn = document.querySelectorAll(".searchIn");/*搜索*/
let newList = document.querySelectorAll(".newlist"); /*新闻列表*/
let hotNews = document.querySelector(".hot"); /*热点新闻*/
let carouselWrap = document.querySelector(".wrap"); /*轮播图容器*/
let carousel = document.querySelector(".carousel"); /*轮播图容器*/
let ul = document.querySelector(".ul"); /*轮播图圆点容器*/
let left = document.querySelector(".left"); /*轮播图左按钮*/
let right = document.querySelector(".right"); /*轮播图右按钮*/
let cont; /*轮播图*/
let begin = 1;
let index = 0;
let timer;
let dot;
fn1(`./php/database.php`, `name=全部&begin=0`).then(res => createDom(res));
for (var i = 0; i < aArr.length; i++) {
aArr[i].onclick = function () {
for (var i = 0; i < aArr.length; i++) {
aArr[i].setAttribute("class", "");
}
this.classList.add("active");
let text = this.innerText;
res=[];
begin = 1;
fn1(`./php/database.php`, `name=${text}&begin=0`).then(res => createDom(res));
}
}
function createDom(data) {
res = res.concat(data.slice(0, data.length - 1));
row.innerHTML = '';
for (var i = 0; i < res.length; i++) {
let a = document.createElement("a");
a.setAttribute("href", `./html/newsDetail.html?id=${res[i][0]}`);
a.setAttribute("class", "detail");
a.setAttribute("target", "_blank");
// 列
let column = document.createElement("div");
column.setAttribute("class", "column col-md-4 col-sm-6 col-xs-6");
// 标题
let divTitle = document.createElement("div");
divTitle.setAttribute("class", "title");
// 图片外容器
let divImg = document.createElement("div");
divImg.setAttribute("class", "img");
// 图片
let img = document.createElement("img");
// 标题
let h2 = document.createElement("h2");
let text = document.createTextNode(res[i][1]);
//设置数据
img.setAttribute("src", res[i][2].split(",")[0]);
img.setAttribute("alt", res[i][1]);
a.appendChild(divTitle);
divTitle.appendChild(h2);
h2.appendChild(text);
a.appendChild(divImg);
divImg.appendChild(img);
column.appendChild(a);
frage.appendChild(column);
}
username[0].innerText = data[data.length - 1] || '新用户';
row.appendChild(frage);
}
/*加载热点新闻*/
fn1(`./php/hotNews.php`)
.then(data => {
createHotNewsDom(data);
createCarouselDom(data);
}
);
/*创建热点新闻*/
function createHotNewsDom(data){
let frage = document.createDocumentFragment();
for (var i = 0; i < data.length; i++) {
let li = document.createElement("li");
let a = document.createElement("a");
let span = document.createElement("span");
let spanNum = document.createElement("span");
span.innerText = i + 1;
spanNum.innerText = data[i][2];
a.setAttribute("href", `./html/newsDetail.html?id=${data[i][0]}`);
a.setAttribute("target", `_blank`);
a.innerText = data[i][1];
li.appendChild(span);
li.appendChild(a);
frage.appendChild(li);
}
hotNews.appendChild(frage);
}
/*创建轮播*/
function createCarouselDom(data){
let frage = document.createDocumentFragment();
for (var i = 0; i < data.length; i++) {
let li = document.createElement("li");
let dotli = document.createElement("li");
let a = document.createElement("a");
let img = document.createElement("img");
let span = document.createElement("span");
data[i][3] = data[i][3].split(",")[0];
a.setAttribute("href", `./html/newsDetail.html?id=${data[i][0]}`);
a.setAttribute("target", `_blank`);
img.setAttribute("src", `${ data[i][3] }`);
li.setAttribute("class", "cont");
if(i == index){
li.classList.add("active");
dotli.setAttribute("class", `active`);
}
span.innerText = data[i][1];
a.appendChild(span);
a.appendChild(img);
li.appendChild(a);
frage.appendChild(li);
ul.appendChild(dotli);
}
carouselWrap.appendChild(frage);
cont = document.querySelectorAll(".cont");
dot = document.querySelectorAll(".ul li");
start(true, index);
bindClick();
}
function bindClick(){
let dot = document.querySelectorAll(".ul li");
let len = dot.length;
for (var i = 0; i < len; i++) {
dot[i].onclick = (function(j){
return ()=>{
start(true, j);
};
})(i);
}
right.onclick = function(){
start(true, index);
};
left.onclick = function(){
start(false, index);
};
}
/**
* [start description]
* @param {[type]} flag [控制方向]
* @param {[type]} s [位置]
* @return {[type]} [description]
*/
function start(flag, s) {
index = s;
play(flag);
clearInterval(timer);
timer = setInterval(function(){
play(flag);
}, 2000);
}
function play(flag){
let len = cont.length;
if(index >= len){
index = 0;
}
if(index < 0){
index = len - 1;
}
for (var i = 0; i < len; i ++) {
cont[i].classList.remove("active");
dot[i].classList.remove("active");
}
cont[index].classList.add("active");
dot[index].classList.add("active");
if(flag){
++ index;
}else {
-- index;
}
}
carousel.onmouseenter = function(){
clearInterval(timer);
}
carousel.onmouseleave = function(){
clearInterval(timer);
timer = setInterval(function(){
play(true);
}, 2000);
}
/*异步加载*/
function checkImgs(columns) {
let column = Array.from(columns);
let len = column.length;
if (isInSight()) {
loadImg();
begin ++;
return;
}
}
function loadImg(e) {
let text = document.getElementsByClassName('active')[0].innerText;
fn1(`./php/database.php`, `name=${text}&begin=${begin}`)
.then(res => createDom(res));
}
function isInSight() {
const clientHeight = window.innerHeight;
let top = document.documentElement.scrollTop;
return ((clientHeight + top) / clientHeight) >= begin;
}
function throttle(cb, delay){
var now,
last = 0;
return function(e){
now = Date.now();
if(now - last >= delay){
cb.apply(this, [e]);
last = now;
}
}
}
window.onscroll = function () {
let column = document.querySelectorAll(".column");
if(column.length > 0){
throttle(checkImgs(column), 300);
}
}
let allNews = [];
fn1(`./php/queryAllNews.php`).then(res => allNews = res);
searchIn[0].oninput = boundance(searchNews, 300);
function boundance(fn, time) {
let timer;
return function (e) {
clearTimeout(timer);
timer = setTimeout(()=> {
fn.apply(this, [e]);
}, time);
}
}
function searchNews(e) {
let inpVal = this.value.trim();
let arrNews = [];
let cloneAllNews;
if(inpVal.length > 0){
let reg = new RegExp(inpVal, "gi");
cloneAllNews = JSON.parse(JSON.stringify(allNews));
cloneAllNews.forEach((val)=>{
if(reg.test(val[1])){
val[1] = val[1].replace(inpVal, `<mark>${inpVal}</mark>`);
arrNews.push(val);
}
});
createSearchDom(arrNews);
arrNews = [];
}else {
newList[0].innerHTML = '';
}
}
function createSearchDom(data) {
newList[0].innerHTML = '';
let frage = document.createDocumentFragment();
for (var i = 0; i < data.length; i++) {
let li = document.createElement("li");
let a = document.createElement("a");
a.innerHTML = data[i][1];
a.setAttribute("href", `http://localhost:800/news/html/newsDetail.html?id=${data[i][0]}`);
a.setAttribute("target", '_blank');
li.setAttribute("class", 'list');
li.appendChild(a);
frage.appendChild(li);
}
newList[0].appendChild(frage);
}
</script>
</body>
</html>