Skip to content

Commit c5b005a

Browse files
committed
fix bug
1 parent fdf752a commit c5b005a

File tree

3 files changed

+51
-47
lines changed

3 files changed

+51
-47
lines changed

css/main.css

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,20 @@ body * {
3737

3838
body {
3939
background: -webkit-radial-gradient(50% 150%,
40-
#00a5bc 0%,
41-
#206b81 10%,
42-
#21687e 35%,
40+
#00a5cc 0%,
41+
#206b99 10%,
42+
#216888 35%,
4343
#031b31 70%,
4444
#000 100%);
4545
}
4646

4747
/* content */
4848

4949
.content {
50-
position: absolute;
5150
width: 100%;
5251
height: 100%;
5352
margin: 0 auto;
5453
overflow: hidden;
55-
top: 0;
56-
left: 0;
5754
}
5855

5956
.content.loading *{
@@ -223,7 +220,7 @@ body {
223220
#s2 {
224221
z-index: 5;
225222
width: 30px;
226-
position: fixed;
223+
position: absolute;
227224
top: 18px;
228225
left: 18px;
229226
opacity: .8
@@ -336,21 +333,11 @@ body {
336333
color: #fff;
337334
vertical-align: top;
338335
-webkit-user-select: none;
336+
transition:.3s;
339337
}
340338

341-
#main02 .btn:hover {
342-
background: rgba(255, 255, 255, .3);
343-
animation-name:hover;
344-
animation-duration:.5s;
345-
animation-fill-mode:forwards;
346-
}
347-
@keyframes hover{
348-
from{
349-
background: rgba(255, 255, 255, .4);
350-
}
351-
to{
352-
background: rgba(255, 255, 255, .1);
353-
}
339+
#main02 .btn.touched {
340+
background: rgba(255, 255, 255, .4);
354341
}
355342

356343
#main02 .btn::before {
@@ -378,14 +365,14 @@ body {
378365
border-radius:20px;
379366
padding:30px 10px;
380367
text-align:center;
381-
background:rgba(50,100,150,.8);
368+
background:rgba(50,100,150,.9);
382369
color:#fff;
383370
opacity:0;
384371
pointer-events: none;
385372
transition:.3s;
386373
}
387374
#popup.show{
388-
top:22%;
375+
top:17%;
389376
opacity:1;
390377
pointer-events: auto;
391378
}
@@ -401,7 +388,19 @@ body {
401388
}
402389
#saveUrl::selection{
403390
color:#fff;
404-
background:#357;
391+
background:none;
392+
}
393+
#copy{
394+
font-size:1.1rem;
395+
padding:10px 30px;
396+
width:max-content;
397+
margin:20px auto 0;
398+
background:#e50;
399+
border-radius:20px;
400+
}
401+
#copy.copied{
402+
pointer-events: none;
403+
opacity:.7;
405404
}
406405
#popupClose{
407406
position:absolute;

index.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
</head>
2222

2323
<body>
24-
<div class="content">
24+
<div class="content loading">
2525
<div id="menu"></div>
2626
<div id="s1">
2727
<svg viewBox="0 0 73.3 72.2">
@@ -605,8 +605,9 @@ <h4>1234567</h4>
605605
</div>
606606
<div id="popup">
607607
<div id="popupClose"></div>
608-
<h4>成功儲存 ( 點擊可複製連結 )</h4>
609-
<div id="saveUrl" data-clipboard-target="#saveUrl"></div>
608+
<h4>儲存成功</h4>
609+
<div id="saveUrl"></div>
610+
<div id="copy" data-clipboard-target="#saveUrl">複製連結</div>
610611
</div>
611612
</div>
612613

js/main.js

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
//https://webbit.webduino.io/blockly/?demo=default#EqdrNJvwYzQy6
22
~async function () {
3-
4-
// 怪獸定位
3+
// 凱比定位
4+
const content = document.querySelector('.content');
5+
content.classList.remove('loading');
56
const kebbi = document.getElementById('svgKebbi');
67
const circle = document.querySelector('.circle');
7-
const ww = window.innerWidth;
8-
const wh = window.innerHeight;
8+
const ww = content.offsetWidth;
9+
const wh = content.offsetHeight;
910
const ox = (ww - kebbi.offsetWidth) / 2;
1011
const oy = (wh * 0.8 - kebbi.offsetHeight) / 2;
1112
kebbi.style.left = `${ox}px`;
@@ -63,19 +64,29 @@
6364
const popup = document.getElementById('popup');
6465
const popupClose = document.getElementById('popupClose');
6566
const saveUrl = document.getElementById('saveUrl');
66-
new ClipboardJS('#saveUrl');
6767
popupClose.addEventListener('click', () => {
6868
popup.classList.remove('show');
6969
});
7070
saveBtn.addEventListener('click', async function () {
7171
let write = await database.ref('/').push(list);
7272
popup.classList.add('show');
7373
saveUrl.innerText = urlOrigin + '/#' + write.key;
74-
saveUrl.click();
7574
window.history.pushState({}, 0, urlOrigin + '#' + write.key);
7675
document.getSelection().removeAllRanges();
7776
});
7877

78+
// 點擊後複製連結
79+
const copy = document.getElementById('copy');
80+
new ClipboardJS('#copy');
81+
copy.addEventListener('click', () => {
82+
copy.innerText = '複製成功';
83+
copy.classList.add('copied');
84+
setTimeout(() => {
85+
copy.innerText = '複製連結';
86+
copy.classList.remove('copied');
87+
}, 1000);
88+
});
89+
7990
/* firebase 讀檔 */
8091
if (urlHash) {
8192
list = await database.ref(urlHash).once('value').then(result => {
@@ -120,13 +131,11 @@
120131

121132
// 顯示十顆按鈕的文字
122133
const btn = document.querySelectorAll('.btn');
123-
function buttonText() {
124-
btn.forEach(e => {
125-
let name = e.id;
126-
e.innerHTML = `<span>${list[name]}</span>`;
127-
});
128-
}
129-
buttonText();
134+
let btnObj = {};
135+
btn.forEach(e => {
136+
btnObj[e.id] = document.getElementById(e.id);
137+
e.innerHTML = `<span>${list[e.id]}</span>`;
138+
});
130139

131140
// 暫存到 localStorage 的函式
132141
function save(val) {
@@ -142,12 +151,9 @@
142151
self.addEventListener('input', () => {
143152
window.history.pushState({}, 0, urlOrigin);
144153
list[m] = self.value;
145-
btn.forEach(ele => {
146-
if (ele.id == m) {
147-
ele.innerHTML = `<span>${self.value}</span>`;
148-
}
149-
});
150-
buttonText();
154+
if (btnObj[m]) {
155+
btnObj[m].innerHTML = `<span>${self.value}</span>`;
156+
}
151157
save(list);
152158
if (m == 'topic2') {
153159
mqttGet(list.topic2);
@@ -163,7 +169,6 @@
163169
}
164170
// 發送 mqtt 訊號
165171
const mqtt = async function (topic, msg) {
166-
console.log(topic,list.topic1);
167172
if (topic == list.topic1) {
168173
webduinoBroadcastor.send({
169174
topic: topic,
@@ -178,7 +183,6 @@
178183
const mqttGet = async function (topic) {
179184
await webduinoBroadcastor.onMessage(topic, async (msg) => {
180185
if (topic == list.topic2) {
181-
console.log(msg);
182186
clearTimeout(messageTimer);
183187
messageH4.innerText = msg;
184188
message.classList.add('show');

0 commit comments

Comments
 (0)