-
Notifications
You must be signed in to change notification settings - Fork 0
/
news.html
172 lines (169 loc) · 5.08 KB
/
news.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
<title>NEWS - Madhav</title>
<link rel="stylesheet" href="style.css">
<style>
article{
padding: 20px;
}
#articles-ul{
list-style: none;
padding-left: 0;
margin: 0;
}
#articles-ul a{
display: flex;
padding: 20px;
border-radius: 30px;
align-items: flex-start;
text-decoration: none;
color: white;
transition: all 0.3s;
}
#articles-ul a:hover{
backdrop-filter: blur(20px);
box-shadow: 10px 10px 20px rgba(0, 0, 0, 0.5);
}
#articles-ul a:hover>img{
box-shadow: 10px 10px 10px rgba(0, 0, 0, 0.5);
}
#articles-ul>li:not(:last-child){
margin-bottom: 30px;
}
#articles-ul>li:nth-child(2n)>a{
flex-direction: row-reverse;
}
img{
width: 100%;
max-width: 400px;
aspect-ratio: 4/3;
object-fit: cover;
overflow: hidden;
border-radius: 20px;
flex-shrink: 0;
transition: all 0.6s;
}
.info{
flex-grow: 1;
}
h1{
margin-top: 0;
}
@media only screen and (min-width: 600px) {
#articles-ul>li:nth-child(2n-1) .info{
margin-left: 20px;
}
#articles-ul>li:nth-child(2n) .info{
margin-right: 20px;
}
}
@media only screen and (max-width: 600px) {
#articles-ul a{
flex-direction: column !important;
}
img{
max-width: 100%;
}
}
.news-ul{
list-style: none;
padding-left: 0;
margin-top: 0;
margin-bottom: 0;
}
.news-ul>li:not(:last-child){
margin-bottom: 1em;
}
.title{
font-size: 1.5em;
font-weight: bold;
}
.auth{
font-style: italic;
}
.auth::before{
content: "~";
}
.header-ul{
display:none;
}
header{
background-image: url(./images/white_lines.png);
background-repeat:no-repeat;
margin-left: auto;
margin-right:50px;
cursor:pointer;
}
</style>
</head>
<body>
<header>
<ul class="header-ul">
<li><a href="/">MADHAV</a></li>
<li><a href="analyze.html">ANALYZE</a></li>
<li><a href="music.html">MUSIC</a></li>
<li><a href="news.html">NEWS</a></li>
<li><a href="game.html">GAME</a></li>
<li><a href="about.html">ABOUT US</a></li>
</ul>
</header>
<main style="flex-grow:1">
<article>
<ul id="articles-ul">
<li>
<a href="">
<img src="" alt="">
<div class="info">
<ul class="news-ul">
<li class="title"></li>
<li class="des"></li>
<li class="auth"></li>
<li class="date"></li>
</ul>
</div>
</a>
</li>
</ul>
</article>
</main>
</body>
<script src="jquery-3.7.1.min.js"></script>
<script>
document.querySelector("header").addEventListener("click", function() {
var headerUl = document.querySelector(".header-ul");
var head = document.querySelector("header");
if (headerUl.style.display === "none") {
headerUl.style.display = "flex";
head.style.backgroundImage = "none";
} else {
headerUl.style.display = "none";
}
});
$(document).ready(function(){
var url = "https://newsapi.org/v2/everything?q=depression&apiKey=7fa5cddcf74d45e0826c93ac4b5009d8";
$.get(url, function(data){
var articles = $("#articles-ul");
var li = articles.find("li").first();
articles.empty();
if(data.status == "ok"){
$.each(data.articles, function(i, article){
row = li.clone();
row.find("a").attr("href", article.url);
row.find("img").attr("src", article.urlToImage);
row.find(".title").html(article.title);
row.find(".des").html(article.description);
row.find(".auth").html(article.author);
row.find(".date").html(article.publishedAt);
articles.append(row);
});
}else{
alert("Couldn't connect to server")
}
})
})
</script>
</html>