๐ ️ [์ต์ข ๊ฐ์ด๋] ๋ธ๋ก๊ทธ์คํ(Blogger)์ Google ํธ๋ ๋ ์คํฌ๋กค ๋ด์ค ํฐ์ปค ์ฝ์ ํ๊ธฐ
๐ ๋ ธ๋ ์์ด ์๋จ ์์ญ์ '์ค์๊ฐ ํธ๋ ๋'๋ก ์ฑ์ฐ๋ ๋ฒ
Google ํธ๋ ๋ ์ค์๊ฐ ๊ฒ์์ด(RSS ํผ๋)๋ฅผ ๋ธ๋ก๊ทธ ์๋จ์ ํ๋ฌ๊ฐ๊ฒ ๋ฐฐ์นํ๋ ๊ฒ์ ๋ ์์ ์์ ์ ์ฌ๋ก์ก๊ณ ์์์ฑ ์๋ ์ฃผ์ ๋ก ํธ๋ํฝ์ ์ ๋ํ๋ ๊ฐ์ฅ ํจ๊ณผ์ ์ธ ๋ฐฉ๋ฒ ์ค ํ๋์ ๋๋ค.
์ด ๊ฐ์ด๋๋ ๋ณต์กํ API ์ฐ๋ ์์ด, ๋ธ๋ก๊ทธ์คํ์ HTML/JavaScript ์์ ฏ๊ณผ ๋ง์ถคํ CSS/JS ์ฝ๋๋ง์ ์ฌ์ฉํ์ฌ ์๋จ์ ์ ๋ฌธ์ ์ธ ๋ด์ค ํฐ์ปค(Ticker)๋ฅผ ๊ตฌํํ๋ ์ต์ข ์ ์ฐจ์ ๋๋ค.
| ์ค๋น๋ฌผ | ๋ด์ฉ |
| RSS ํผ๋ URL | ๋ํ๋ฏผ๊ตญ ์ผ๋ณ ์ธ๊ธฐ ๊ฒ์์ด RSS ์ฃผ์: https://trends.google.com/trends/trendingsearches/daily/rss?geo=KR |
| ํต์ฌ ๊ธฐ์ | HTML (๊ตฌ์กฐ) + CSS (๋ชจ์) + JavaScript (๋ถ๋๋ฌ์ด ์คํฌ๋กค) |
1๋จ๊ณ: CSS ์ฝ๋ ์ฝ์ (์คํฌ๋กค๋ฐ์ ๋ชจ์๊ณผ ํ ์ก๊ธฐ)
์คํฌ๋กค๋ฐ์ ๋์์ธ๊ณผ ์ ๋๋ฉ์ด์ ํ์ ์ก๋ CSS ์ฝ๋๋ฅผ ๋ธ๋ก๊ทธ์คํ ํ ๋ง์ ์ถ๊ฐํฉ๋๋ค.
[๋ธ๋ก๊ทธ์คํ ๊ด๋ฆฌ] → [ํ ๋ง] → **[HTML ์์ ]**์ผ๋ก ์ด๋ํฉ๋๋ค.
<b:skin>ํ๊ทธ ๋ด๋ถ ๋๋</head>ํ๊ทธ ์์ ๋ค์ CSS ์ฝ๋๋ฅผ ๋ณต์ฌํ์ฌ ๋ถ์ฌ๋ฃ์ต๋๋ค.
/* ์ค์๊ฐ ๊ฒ์์ด ์คํฌ๋กค๋ฐ CSS */
.trending-ticker-wrap {
display: flex;
align-items: center;
height: 35px; /* ๋์ด ์ค์ */
background-color: #f7f7f7; /* ๋ฐฐ๊ฒฝ์ */
padding: 0 15px;
overflow: hidden; /* **ํ์**: ๋์น๋ ๋ด์ฉ ์จ๊น */
border-bottom: 1px solid #ddd;
margin-bottom: 20px;
}
.trending-ticker-wrap span {
font-weight: bold;
color: #e60000; /* ๊ฐ์กฐ ์์ */
margin-right: 15px;
flex-shrink: 0;
}
#scrolling-keywords {
width: 100%;
overflow: hidden;
position: relative;
}
#scrolling-keywords ul {
list-style: none;
margin: 0;
padding: 0;
white-space: nowrap; /* ์ค ๋ฐ๊ฟ ๋ฐฉ์ง */
/* JS๊ฐ transform์ ์ ์ดํฉ๋๋ค. CSS ์ ๋๋ฉ์ด์
์ ์ฌ๊ธฐ์ ์ ๊ฑฐ๋ฉ๋๋ค. */
cursor: pointer;
}
#scrolling-keywords li {
display: inline-block;
margin-right: 30px;
}
#scrolling-keywords a {
text-decoration: none;
color: #333;
font-size: 14px;
}
์ฐ์ธก ์๋จ์ [์ ์ฅ] ๋ฒํผ์ ๋๋ฌ CSS ๋ณ๊ฒฝ ์ฌํญ์ ์ ์ฅํฉ๋๋ค.
2๋จ๊ณ: HTML ๊ตฌ์กฐ ๋ฐ JavaScript ์ฝ๋ ์ฝ์ (๋ฐ์ดํฐ์ ์์ง์ ๊ตฌํ)
์ด ๋จ๊ณ์์๋ HTML ๊ตฌ์กฐ์ ์คํฌ๋กค๋ง์ ๋ด๋นํ JS ์ฝ๋๋ฅผ HTML/JavaScript ์์ ฏ ํ๋์ ๋ชจ๋ ๋ฃ์ต๋๋ค.
[๋ธ๋ก๊ทธ์คํ ๊ด๋ฆฌ] → [๋ ์ด์์]์ผ๋ก ์ด๋ํฉ๋๋ค.
์คํฌ๋กค๋ฐ๋ฅผ ์์น์ํฌ ์์ญ(์: 'Header' ์๋)์์ [๊ฐ์ ฏ ์ถ๊ฐ]๋ฅผ ํด๋ฆญํฉ๋๋ค.
๋ชฉ๋ก์์ [HTML/JavaScript]๋ฅผ ์ ํํฉ๋๋ค.
์์ ฏ ์ค์ ์ฐฝ์ '์ฝํ ์ธ ' ์์ญ์ ๋ค์ HTML ๋ฐ JS ์ฝ๋ ์ ์ฒด๋ฅผ ๋ณต์ฌํ์ฌ ๋ถ์ฌ๋ฃ์ต๋๋ค.
๐ HTML ๋ฐ JavaScript ์ฝ๋
<div class="trending-ticker-wrap">
<span>๐ Google ์ค์๊ฐ ํธ๋ ๋</span>
<div id="scrolling-keywords">
<ul>
<li><a href="https://www.google.com/search?q=ํค์๋1" target="_blank">์ค๋์ ํ ์ฃผ์ 1</a></li>
<li><a href="https://www.google.com/search?q=ํค์๋2" target="_blank">Google ํธ๋ ๋ 2์</a></li>
<li><a href="https://www.google.com/search?q=ํค์๋3" target="_blank">์ธ๊ธฐ ํค์๋ 3์ (์ต์ )</a></li>
<li><a href="https://www.google.com/search?q=ํค์๋4" target="_blank">๊ธ์์น ์ด์ ํค์๋</a></li>
<li><a href="https://www.google.com/search?q=ํค์๋5" target="_blank">์ถ๊ฐ ์ธ๊ธฐ ๊ฒ์์ด</a></li>
</ul>
</div>
</div>
<script>
function startTickerScroll() {
const scrollContainer = document.getElementById('scrolling-keywords');
if (!scrollContainer) return;
const ul = scrollContainer.querySelector('ul');
if (!ul) return;
// 1. ๋ฆฌ์คํธ ๋ด์ฉ ๋ณต์ (๋๊น ์๋ ๋ฃจํ๋ฅผ ์ํจ)
ul.innerHTML += ul.innerHTML;
let position = 0;
// ์คํฌ๋กค ์๋ ์ค์ (์ซ์๊ฐ ์์์๋ก ๋๋ฆฌ๊ณ ๋ถ๋๋ฌ์)
const scrollSpeed = 0.5;
// ์๋ณธ ์ฝํ
์ธ ์ ๋๋น ๊ณ์ฐ
const totalContentWidth = ul.scrollWidth / 2;
function scrollTick() {
// 2. ์ฝํ
์ธ ๋ฅผ ์ผ์ชฝ์ผ๋ก ์ด๋
position -= scrollSpeed;
// 3. ๋ฃจํ ์ฒ๋ฆฌ: ์๋ณธ ๋ชฉ๋ก์ด ์ง๋๊ฐ๋ฉด ์์น ๋ฆฌ์
if (position < -totalContentWidth) {
position += totalContentWidth;
}
// CSS Transform์ผ๋ก ์์น ๋ณ๊ฒฝ (๋ถ๋๋ฌ์ด ์ ๋๋ฉ์ด์
)
ul.style.transform = `translateX(${position}px)`;
requestAnimationFrame(scrollTick);
}
// ๋ง์ฐ์ค ์ค๋ฒ ์ ๋ฉ์ถค, ๋ง์ฐ์ค ์์ ์ ๋ค์ ์์ (UX ๊ฐ์ )
scrollContainer.addEventListener('mouseenter', () => {
ul.style.animationPlayState = 'paused';
});
scrollContainer.addEventListener('mouseleave', () => {
ul.style.animationPlayState = 'running';
});
// ์ ๋๋ฉ์ด์
์์
requestAnimationFrame(scrollTick);
}
// ํ์ด์ง ๋ก๋ ํ ์คํ ๋ณด์ฅ
if (document.readyState === 'loading') {
window.addEventListener('load', startTickerScroll);
} else {
startTickerScroll();
}
</script>
[์ ์ฅ] ๋ฒํผ์ ํด๋ฆญํ์ฌ ์์ ฏ์ ์ ์ฅํฉ๋๋ค.
3๋จ๊ณ: ์ต์ข ํ์ธ ๋ฐ ๋ฐ์ดํฐ ๊ด๋ฆฌ
[๋ ์ด์์] ํ์ด์ง์์ ์์ ฏ์ด ์ํ๋ ์๋จ ์์น์ ์๋์ง ํ์ธํ๊ณ , [์ ์ฅ]์ ๋๋ฌ ์ต์ข ๋ฐฐ์นํฉ๋๋ค.
๋ธ๋ก๊ทธ๋ฅผ ์๋ก๊ณ ์นจํ์ฌ ์คํฌ๋กค๋๋ ๋ด์ค ํฐ์ปค๊ฐ ๋๊น ์์ด ๋ถ๋๋ฝ๊ฒ ์์ง์ด๋์ง ํ์ธํฉ๋๋ค.
⚠️ ํต์ฌ ๊ด๋ฆฌ ๋ฃจํด: ๋ฐ์ดํฐ ์ ๋ฐ์ดํธ
์ด ์์คํ ์ JavaScript๋ก ์คํฌ๋กค๋ง ํจ๊ณผ๋ง ์๋ํํ๋ฉฐ, ํธ๋ ๋ ๋ฐ์ดํฐ๋ ์๋ ์ ๋ฐ์ดํธ๋์ง ์์ต๋๋ค.
๊ด๋ฆฌ ์ฃผ๊ธฐ: ๋งค์ผ ๋๋ 2~3์ผ์ ํ ๋ฒ์ฉ
https://trends.google.com/trends/trendingsearches/daily/rss?geo=KRRSS ํผ๋๋ฅผ ํ์ธํฉ๋๋ค.์ ๋ฐ์ดํธ: 2๋จ๊ณ์์ ์ฝ์ ํ๋ HTML/JavaScript ์์ ฏ์ผ๋ก ๋์๊ฐ์
<ul>๋ชฉ๋ก ์์ ํค์๋์ ๋งํฌ๋ฅผ ์๋์ผ๋ก ์์ ํด ์ฃผ์ด์ผ ํฉ๋๋ค.
#๊ฐ๋ ํฌ๋ฐ์ด #ganatoday
๊ทธ๋ฆฐ์ํ๋ก