ë³´ì 컨í ì¤í¸: ì´ ê¸°ë¥ì ì¼ë¶ ëë 모ë ì§ì ë¸ë¼ì°ì ì ë³´ì 컨í ì¤í¸ (HTTPS)ììë§ ì¬ì©í ì ììµëë¤.
ëë°ì´ì¤ ë´ ì¹ íê²½ì´ ë°ì í¨ì ë°ë¼ ì¹ììë ë°©í¥ì 측ì í ì ììµëë¤. ì´ë ì¤ë ¥ì ë³í를 í ëë¡ ëë°ì´ì¤ì ë³ì를 측ì í¨ì ë»í©ëë¤. í¹í, ì´ë¬í ì 보를 ë°íì¼ë¡ ëì¤íë ì´ë¥¼ ìëì¼ë¡ íì ìì¼ ëë°ë¡ íë©´ì ì ì§í ì ìì¼ë©°, ì¹ ì½í ì¸ ìì ìì´ë ì¤í¬ë¦°ì ì ê³µí ì ìê² ë©ëë¤.
ì´ë¬í ë°©í¥ ì 보를 ì²ë¦¬í기 ìí´ìë ë ê°ì§ì ìë°ì¤í¬ë¦½í¸ ì´ë²¤í¸ê° íìí©ëë¤. 첫ë²ì§¸ë¡ ë°©í¥ ì´ë²¤í¸ DeviceOrientationEvent
ê° ììµëë¤. ì¬ì©ìê° ëë°ì´ì¤ë¥¼ ì´ëíë©´ì ì기ë íì ê³¼ ê³ ë ë³í를 측ì í ì ììµëë¤.
ëë²ì§¸ë ê°ìëê³ì ë³íì ë°ë¼ ì´ë²¤í¸ë¥¼ ë°ììí¤ë 모ì
ì´ë²¤í¸ DeviceMotionEvent
ê° ììµëë¤. ë°©í¥ì´ ìë ê°ìëì ë³í를 ê°ì§í기 ë문ì ê°ìëê³ ì´ë²¤í¸ìë ë¤ë¦
ëë¤. DeviceOrientationEvent
ë 모ë°ì¼ ì¥ì¹ìì ì주 ì¬ì©ë©ëë¤.
ë°©í¥ì ê°ì§í기 ìí´ìë ì´ ì´ë²¤í¸ë¥¼ addEventListenerì ì§ì í´ì£¼ë©´ ë©ëë¤. deviceorientation
:
window.addEventListener("deviceorientation", handleOrientation, true);
ì´ë²¤í¸ë¥¼ ë±ë¡í í, 리ì¤ë í¨ìë ì ë°ì´í¸ë ë°©í¥ì 주기ì ì¼ë¡ í¸ì¶íê² ë©ëë¤.
ë°©í¥ ì´ë²¤í¸ìë ë¤ì 4ê°ì§ ê°ì´ í¬í¨ë©ëë¤.
DeviceOrientationEvent.absolute
DeviceOrientationEvent.alpha
DeviceOrientationEvent.beta
DeviceOrientationEvent.gamma
ì´ë²¤í¸ í¸ë¤ë¬ í¨ìë ë¤ìê³¼ ê°ì´ ì¬ì©ë©ëë¤.
function handleOrientation(event) {
const absolute = event.absolute;
const alpha = event.alpha;
const beta = event.beta;
const gamma = event.gamma;
// ë°©í¥ ë°ì´í°ë¡ ì¬ì©ì ìì
ìí
}
ë°©í¥ ê° ì¤ëªì°¸ê³ : parallax ë ê°ìëê³ì ìì´ë¡ì¤ì½í를 모ë°ì¼ìì ì²ë¦¬í기 ìí í´ë¦¬í ì ëë¤. ëë°ì´ì¤ í¸íì± ì²ë¦¬ë¥¼ 극복íëë° ì ì©í ì ììµëë¤.
ê° ì¶ì ê°ì ì¢í íë ìì 기ì¤ì¼ë¡ 주ì´ì§ ì¶ì ì¤ì¬ì¼ë¡ ë³í íì ëì ëíë ëë¤. ì´ë ìëì ìì½ë ë°©í¥ê³¼ 모ì ë°ì´í° ì¤ëª ìí°í´ìì ìì¸íê² ì¤ëª ë©ëë¤.
DeviceOrientationEvent.alpha
Zì¶ì ì¤ì¬ì¼ë¡ ìì§ìì ëíë
ëë¤. 0ìì 360 ì¬ì´ì ê°ì ê°ì§ë degree ë¨ìë¡ í기ë©ëë¤.DeviceOrientationEvent.beta
Xì¶ì ì¤ì¬ì¼ë¡ ìì§ìì ëíë
ëë¤. -180ìì 180ë ì¬ì´ì ê°ì ê°ì§ë©° ëë°ì´ì¤ì ìë©´ê³¼ ë·ë©´ì ìì§ìì ëíë
ëë¤.DeviceOrientationEvent.gamma
Yì¶ì ì¤ì¬ì¼ë¡ ìì§ìì ëíë
ëë¤. -90ìì 90ë ë´ì ì¬ì´ì ê°ì ê°ì§ë©° ëë°ì´ì¤ì ì¢ì° ìì§ìì ëíë
ëë¤.ì´ ìì ë deviceorientation
ì´ë²¤í¸ë¥¼ ì§ìíë 모ë ë¸ë¼ì°ì ì ë°©í¥ì ê°ì§í ì ìë ëë°ì´ì¤ìì ìëí©ëë¤.
ìë ìì ììë ë°°ê²½ì ìë ê³µì íìí©ëë¤.
<div class="garden">
<div class="ball"></div>
</div>
ëë°ì´ì¤ë¥¼ ë°ë¥ì ëê³ XYì¶ì ë°ë¼ íì íë©´ ê³µì´ ê°ê° ìíì¢ì°ë¡ ìì§ì
ëë¤.
<pre class="output"></pre>
ë°°ê²½ì ëë¹ë 200í½ì ë¨ìê³ ê³µì ì¤ìì ìì¹í©ëë¤.
.garden {
position: relative;
width: 200px;
height: 200px;
border: 5px solid #ccc;
border-radius: 10px;
}
.ball {
position: absolute;
top: 90px;
left: 90px;
width: 20px;
height: 20px;
background: green;
border-radius: 100%;
}
ì´ì ì¥ì¹ë¥¼ ìì§ì´ë©´ì ê³µì ìì§ì¼ ì ììµëë¤.
const ball = document.querySelector(".ball");
const garden = document.querySelector(".garden");
const output = document.querySelector(".output");
const maxX = garden.clientWidth - ball.clientWidth;
const maxY = garden.clientHeight - ball.clientHeight;
function handleOrientation(event) {
let x = event.beta; // ê°ëì ë²ìë [-180,180)
let y = event.gamma; // ê°ëì ë²ìë [-90,90)
output.textContent = `beta: ${x}\n`;
output.textContent += `gamma: ${y}\n`;
// ì¥ì¹ë¥¼ ë°ëë¡ ì¸ì§íì§ ìê² í기 ìí´
// X ê°ì ë¤ìê³¼ ê°ì´ ì íí©ëë¤. [-90,90]
if (x > 90) {
x = 90;
}
if (x < -90) {
x = -90;
}
// ê³ì°ì í¸íê² í기 ìí´ ë¤ìê³¼ ê°ì´ ë²ì를 ì¡°ì í©ëë¤.
// xì yë [0,180]
x += 90;
y += 90;
// 10ì ê³µì ì ë° í¬ê¸°ì
ëë¤.
// ê³µì ì§ì ì ì¤ìì¼ë¡ ì´ëí기 ìí©ì
ëë¤.
ball.style.left = `${(maxY * y) / 180 - 10}px`; // yì¶ì ì¤ì¬ì¼ë¡ íì íë©´ ê³µì ìí ë°©í¥ì¼ë¡ ì´ëí©ëë¤.
ball.style.top = `${(maxX * x) / 180 - 10}px`; // xì¶ì ì¤ì¬ì¼ë¡ íì íë©´ ê³µì ìì§ ë°©í¥ì¼ë¡ ì´ëí©ëë¤.
}
window.addEventListener("deviceorientation", handleOrientation);
ì¬ê¸°ë¥¼ í´ë¦íì¬ ìì 를 ì ì°½ìì ì½ëë¤.
모ì ì´ë²¤í¸ ì²ë¦¬ëª¨ì
ì´ë²¤í¸ë ë¤ìê³¼ ê°ì ê²½ì°ë¥¼ ì ì¸íê³ ë ë°©í¥ ì´ë²¤í¸ì ëì¼íê² ìëí©ëë¤. devicemotion
window.addEventListener("devicemotion", handleMotion, true);
ì¤ì ë¡ ë³íë ê²ì ì´ë²¤í¸ 리ì¤ëì íë¼ë¯¸í°ë¡ ì ë¬ë, DeviceMotionEvent
ê°ì²´ ë´ìì ì ê³µëë ì ë³´ì¸ handleMotion()
ì
ëë¤.
모ì ì´ë²¤í¸ë ìë 4ê°ì§ ìì±ì í¬í¨í©ëë¤.
DeviceMotionEvent.acceleration
DeviceMotionEvent.accelerationIncludingGravity
DeviceMotionEvent.rotationRate
DeviceMotionEvent.interval
DeviceMotionEvent
ê°ì²´ë ëë°ì´ì¤ì ìì¹ì ë°©í¥ì ëí ë³ê²½ ìë를 í¬í¨í©ëë¤. ë³ê²½ ì¬íì 3ê°ì ì¶ì¼ë¡ ì ê³µë©ëë¤. (ìì¸í ë´ì©ì ë°©í¥ê³¼ 모ì
ë°ì´í° ì¤ëª
참조íììì¤).
acceleration
ê³¼ accelerationIncludingGravity
ì´ ì¶ë¤ì ë¤ìê³¼ ê°ìµëë¤.
x
ì쪽ìì ë쪽ì¼ë¡ ê°ë ì¶ì ëíë ëë¤.
y
ë¨ìª½ìì ë¶ìª½ì¼ë¡ ê°ë ì¶ì ëíë ëë¤.
z
ë°ë¥ì ìì§ì¸ ì¶ì ëíë ëë¤.
rotationRate
íì ì ê²½ì° ë¤ìê³¼ ê°ìµëë¤.
alpha
íë©´ì ìì§ì¸ ì¶ì ë°ë¼ íì ìë를 ëíë ëë¤.
beta
ì¼ìª½ìì ì¤ë¥¸ìª½ì¼ë¡ ê°ë ì¶ì ë°ë¼ íì ìë를 ëíë ëë¤.
gamma
ëë°ì´ì¤ë¥¼ íë©´ì¼ë¡ ëì ìíìì ìëìì ìë¡ ê°ë ì¶ì ë°ë¼ íì ìë를 ëíë ëë¤.
ë§ì§ë§ì¼ë¡, interval
ë ëë°ì´ì¤ìì ë°ì´í°ë¥¼ ê°ì ¸ì¤ë ê°ê²©ì ëíë
ëë¤.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4