๊ตฌ๊ธ ๊ด๊ณ ์ฝ๋ ํ์ฉํ ์ฌ์ด๋ ๋ฐฐ๋ ์ ์
๊ตฌ๊ธ ๊ด๊ณ ์ฝ๋๋ฅผ ํ์ฉํด์ ์ฌ์ด๋ ๋ฐฐ๋ ๊ด๊ณ ์ ์ ๋ฐฉ๋ฒ์ ๋๋ค. ๋ชจ๋ฐ์ผ ์ํ๊ฐ ๋๋ฉด ๋ฐฐ๋์ฝ๋ ์์ฒด๋ฅผ ์คํ์ด ์ ๋๊ฒ ์์ ํ์ต๋๋ค. ์ผ๋ฐ์ ์ผ๋ก ์ฌ์ฉ ์ ๊ตณ์ด ๋ชจ๋ฐ์ผ์์ ๋ณด์ด์ง ์๋ ์ฌ์ด๋ ๋ฐฐ๋ ๊ด๊ณ ๋ฅผ ์ญ์ ๊น์ง ํ ํ์๋ ์์ง๋ง ๋ฉ๋ชจ๋ฆฌ๋ฅผ ์๋ชจํ๊ธฐ๋ ํ๊ณ ๋ ํฐ ๋ฌธ์ ๋ ์ฝ์์ ์๋ฌ ๋ฉ์์ง๋ฅผ ํ์ํ๊ธฐ ๋๋ฌธ์ ๊ฒ์๋ด์ ์ค๋ฅ๋ฅผ ์ธ์ํด์ ์ฑ๋ฅ ๊ฒ์ฌ ์ ์๋ฅผ ํ๋ฝ์ํต๋๋ค.
๊ด๊ณ ๋ฒ ๋ ์ฝ๋
์ฌ์ด๋ ๋ฐฐ๋ CSS ์ฝ๋ ์ค๋ช
์๋ ์ฌ์ด๋ ๋ฐฐ๋ ์ฝ๋๋ฅผ ์์ ์ ๊ด๊ณ ์ฝ๋์ ๋ง๊ฒ ์์ ํด์ ์ฌ์ฉํ์๋ฉด ๋ฉ๋๋ค. ์ฌ์ด๋ ๋ฐฐ๋ ๊ด๊ณ ์ ์์น๋ ๋ณ๊ฒฝํด์ ์ฌ์ฉํ์๊ณ ํ์ด์ง์ ํด์๋์ ํฌ๊ธฐ๋ฅผ ๊ณ์ฐํด์ ์ค์ ํ์๋ฉด ์ฌ์ด๋ ๋ฐฐ๋ ๊ด๊ณ ์ ์์น๋ฅผ ์ค์ ํ ์ ์์ต๋๋ค. ์ต๋ํ์ ๋ ธ์ถ๊ณผ ์ฌ์ฉ์์ ๋ถํธํจ์ ์ต๋ํ์ผ๋ก ์ค์ด๋๋ก ๊ด๊ณ ์ ์์น๋ฅผ ์ค์ ํ์๋ฉด ๋ฉ๋๋ค.
์ค๋ฅธ์ชฝ ๊ณ ์ ์ฌ์ด๋ ๋ฐฐ๋
position: absolute; /* ์์๋ฅผ ์ ๋ ์์น์ ๋ฐฐ์น */
width: 160px; /* ์์์ ๋๋น ์ค์ */
right: 50%; /* ์์๋ฅผ ์ค๋ฅธ์ชฝ์์ 50% ๋จ์ด์ง ์์น์ ๋ฐฐ์น */
top: 60px; /* ์์๋ฅผ ์์์ 60px ๋จ์ด์ง ์์น์ ๋ฐฐ์น */
margin-right: 470px; /* ์์์ ์ค๋ฅธ์ชฝ ์ฌ๋ฐฑ ์ค์ */ ์ด๋ถ๋ถ์ ์์ ํ์๋ฉด ์์น ๋ณ๊ฒฝ
z-index: 9999; /* ์์์ z-index ์ค์ , ๋ค๋ฅธ ์์ ์์ ํ์๋๋๋ก ํจ */
transform: translateX(-50%); /* ์์๋ฅผ ์ํ ์ค์์ผ๋ก ์ด๋ */
์ผ์ชฝ ์ฌ์ด๋ ๊ณ ์ ๋ฐฐ๋
position: absolute; /* ์์๋ฅผ ์ ๋ ์์น์ ๋ฐฐ์น */
width: 160px; /* ์์์ ๋๋น ์ค์ */
left: 50%; /* ์์๋ฅผ ์ผ์ชฝ์์ 50% ๋จ์ด์ง ์์น์ ๋ฐฐ์น */
margin-left: 650px; /* ์์์ ์ผ์ชฝ ์ฌ๋ฐฑ ์ค์ */ ์ด๋ถ๋ถ์ ์์ ํ์๋ฉด ์์น ๋ณ๊ฒฝ
top: 60px; /* ์์๋ฅผ ์์์ 60px ๋จ์ด์ง ์์น์ ๋ฐฐ์น */
z-index: 9999; /* ์์์ z-index ์ค์ , ๋ค๋ฅธ ์์ ์์ ํ์๋๋๋ก ํจ */
transform: translateX(-50%); /* ์์๋ฅผ ์ํ ์ค์์ผ๋ก ์ด๋ */
์นด์นด์ค ์ ๋ํ ๊ด๊ณ ์ค์
var adArea = document.createElement('ins');
adArea.className = 'kakao_ad_area'; adArea.style.display = 'block'; // ๊ด๊ณ ์์ญ์ ๋ณด์ด๋๋ก ์ค์
adArea.setAttribute('data-ad-unit', '๊ด๊ณ ์ฝ๋'); // ๊ด๊ณ ๋จ์ ์ค์
adArea.setAttribute('data-ad-width', '160'); // ๊ด๊ณ ๋๋น ์ค์
adArea.setAttribute('data-ad-height', '600'); // ๊ด๊ณ ๋์ด ์ค์
floatLeftElement.appendChild(adArea);
์ฌ์ด๋๋ฐ์ ๋์ ์ด๋๊ณผ ๊ณ ์ ์ค์ ์ผ๋ก ๋ธ๋ก๊ทธ ์์ต ํฅ์ ๋ฐฉ์
์ฌ์ด๋๋ฐ์ ๋ธ๋ก๊ทธ ์์ต๋ธ๋ก๊ทธ์์ ์ฌ์ด๋๋ฐ๋ ์ ๋ณด์ ๊ด๊ณ ๋ฅผ ์ฌ์ฉ์์๊ฒ ๋ ธ์ถํ๋ฉฐ [ ๋ธ๋ก๊ทธ ์์ต ]์ ์ํฅ์ ์ฃผ๋ ์์์ ๋๋ค. ๊ทธ๋ฌ๋ ์ผ๋ถ ์คํจ์ ๋ชจ๋ฐ์ผ์์๋ ์ฌ์ด๋๋ฐ๊ฐ ์ ํ์ ์์๋ก ์
everydayhub.tistory.com
๊ตฌ๊ธ ์ ๋์ผ์ค ๊ด๊ณ ์ฝ๋ ์ค์
var adArea = document.createElement('ins');
adArea.className = 'adsbygoogle'; adArea.style.display = 'block'; // ๊ด๊ณ ์์ญ์ ๋ณด์ด๋๋ก ์ค์
adArea.setAttribute('data-ad-client', 'ca-pub-๊ด๊ณ ํด๋ผ์ด์ธํธ ์ฝ๋'); // ๊ด๊ณ ํด๋ผ์ด์ธํธ ์ค์
adArea.setAttribute('data-ad-slot', '๊ด๊ณ ์ฌ๋กฏ ์ฝ๋'); // ๊ด๊ณ ์ฌ๋กฏ ์ค์
adArea.setAttribute('data-ad-format', 'auto'); // ๊ด๊ณ ํฌ๋งท ์ค์
adArea.setAttribute('data-full-width-responsive', 'true'); // ๊ด๊ณ ์ ๊ฐ๋กํญ ๋ฐ์ํ ์ค์
floatRightElement.appendChild(adArea);
์คํฌ๋ฆฝํธ ์ฝ๋
<style> #floatLeft { position: absolute; width: 160px; right: 50%; top: 60px; margin-right: 470px; z-index: 9999; transform: translateX(-50%); } #floatRight { position: absolute; width: 160px; left: 50%; margin-left: 650px; top: 60px; z-index: 9999; transform: translateX(-50%); } @media (max-width: 1300px) { #floatLeft, #floatRight { display: none; } } </style> <div class="height"> <div id="floatLeft"> <script> if (window.innerWidth > 768) { var floatLeftElement = document.querySelector('#floatLeft'); if (floatLeftElement) { var adArea = document.createElement('ins'); adArea.className = 'kakao_ad_area'; adArea.style.display = 'block'; adArea.setAttribute('data-ad-unit', '๊ด๊ณ ์ฝ๋'); adArea.setAttribute('data-ad-width', '160'); adArea.setAttribute('data-ad-height', '600'); floatLeftElement.appendChild(adArea); var script = document.createElement('script'); script.src = "//t1.daumcdn.net/kas/static/ba.min.js"; script.async = true; document.body.appendChild(script); } } </script> </div> </div> <div class="height"> <div id="floatRight"> <script> if (window.innerWidth > 768) { var floatRightElement = document.querySelector('#floatRight'); if (floatRightElement) { var adArea = document.createElement('ins'); adArea.className = 'adsbygoogle'; adArea.style.display = 'block'; adArea.setAttribute('data-ad-client', 'ca-pub-๊ด๊ณ ์ฝ๋'); adArea.setAttribute('data-ad-slot', '๊ด๊ณ ์ฝ๋'); adArea.setAttribute('data-ad-format', 'auto'); adArea.setAttribute('data-full-width-responsive', 'true'); floatRightElement.appendChild(adArea); var script = document.createElement('script'); script.src = "https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-์ฝ๋"; script.async = true; script.crossOrigin = "anonymous"; document.body.appendChild(script); (adsbygoogle = window.adsbygoogle || []).push({}); } } </script> </div> </div> <script> $(document).ready(function() { if (window.innerWidth > 1300) { var floatPositionLeft = parseInt($("#floatLeft").css('top')); var floatPositionRight = parseInt($("#floatRight").css('top')); $(window).scroll(function() { var scrollTop = $(window).scrollTop(); var newPositionLeft = scrollTop + floatPositionLeft + "px"; var newPositionRight = scrollTop + floatPositionRight + "px"; $("#floatLeft").stop().animate({ "top": newPositionLeft }, 500); $("#floatRight").stop().animate({ "top": newPositionRight }, 500); }).scroll(); } else { $("#floatLeft").hide(); $("#floatRight").hide(); } }); </script>
ํฐ์คํ ๋ฆฌ HTML ๋ฒ ๋์ถ๋ ฅํ์ฉ ๋ฐฉ๋ฒ
ํฐ์คํ ๋ฆฌ HTML ๋ฐฐ๋์ถ๋ ฅ์ ์์ ์ฝ๋๋ฅผ ์์ ํด์ ๋ฃ์ด์ฃผ์๋ฉด ๋ฉ๋๋ค.
๊ตฌ๊ธ ์๋ ๊ด๊ณ ์ฝ๋ ์ค์ ๋ฐฉ๋ฒ
๊ตฌ๊ธ์ ๋์ผ์ค์ ์ ์ํด์ ๊ด๊ณ ๋์ ๋ค์ด๊ฐ์๋ฉด ๊ด๊ณ ๋จ์ ๊ธฐ์ค ๋ฉ๋ด๊ฐ ์์ต๋๋ค.
๋์คํ๋ ์ด ๊ด๊ณ ์ค์
๊ตฌ๊ธ ์ ๋์ผ์ค ์ฝ๋ ์์ฑ๊ธฐ ํ์ฉ
์ ๋์คํ๋ ์ด ๊ด๊ณ ์์ ์์งํ ๊ด๊ณ ๋จ์ ์ด๋ฆ ์ค์ ๊ด๊ณ ํฌ๊ธฐ๋ ๋ฐ์ํ ๋ง๋ค๊ธฐ ๋ฒํผ์ ๋๋ฆ ๋๋ค.
๋จ ํฐ์คํ ๋ฆฌ ๋ธ๋ก๊ทธ์์ ๋ ์ผ๊ด๊ณ ๋ ์ ์ฑ ์๋ฐ์ด๋ผ ์ฌ์ฉํ์๋ฉด ์๋ฉ๋๋ค.