-
Notifications
You must be signed in to change notification settings - Fork 0
/
SNS_practice.html
119 lines (106 loc) · 3.54 KB
/
SNS_practice.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
<!DOCTYPE html>
<html lang="kr">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
* {
margin: 0;
padding: 0;
}
.body {
display: flex;
flex-direction: column;
align-items: center;
}
body {
background-color: ghostwhite;
}
.container {
background-color: ghostwhite;
padding: 20px;
width: 93%;
font-family: 나눔스퀘어_ac;
border-top-color: darkgray;
border-top-style: solid;
}
.text {
background-color: #CCDCDB;
margin-top: 30px;
width: 100%;
font-family: 나눔스퀘어_ac;
display: flex;
flex-direction: column;
align-items: center;
}
.top {
position:fixed; width:100%; top:0; left:0; right:0;margin:0; padding:0; background: #76BFBA;
font-size: 30px; font-style: italic; text-align: center; color: #FFFFFF;
font-family: Cambria;
}
textarea {
margin: 20px;
width: 90%;
}
button {
width: 90%;
margin-bottom:20px;
}
#timeline {
width: 100%;
display: flex;
flex-direction: column;
align-items: center;
margin-top: 20px;
}
p {
background-color: #CCDCDB;
}
</style>
</head>
<body>
<div class="body">
<div class="top">winkstagram</div>
<div class="text">
<textarea name="" id="" cols="150" rows="10"></textarea>
<button onclick="postClick()">작성</button>
</div>
<div id="timeline">
<div class="container">
<h2>작성자</h2>
<p>내용</p>
</div>
</div>
<script>
let postInput = document.querySelector("textarea");
let timeline = document.querySelector("#timeline");
window.onload = async () => {
const postsResponse = await fetch("http://ec2-52-78-131-251.ap-northeast-2.compute.amazonaws.com/feed/",{
method: 'get',
});
const posts = await postsResponse.json();
for(let i=0; i< posts.length; i++)
{
console.log(posts[i]);
post(posts[i].owner, posts[i].content);
}
};
const postClick = async() => {
post('김지성', postInput.value);
};
const post = (name, write) => {
let container = document.createElement('div');
let owner = document.createElement('h2');
let content = document.createElement('p');
owner.appendChild(document.createTextNode(name));
content.appendChild(document.createTextNode(write));
container.setAttribute('class', 'container');
container.appendChild(owner);
container.appendChild(content);
timeline.appendChild(container);
};
</script>
</div>
</div>
</body>
</html>