๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Lect & Tip/javascript, jQuery

๋ชจ๋ฐ”์ผํ™ˆํŽ˜์ด์ง€ ์ฃผ์†Œ์ฐฝ ๊ฐ์ถ”๊ธฐ tip body[orient="portrait"] ,body[orient="landscape"]

by ๋‚ฏ์„ ๊ณต๊ฐ„2019 2020. 6. 8.

๋ชฉ์ฐจ

    [๋ชจ๋ฐ”์ผํ™ˆํŽ˜์ด์ง€ ์ œ์ž‘] ๋ชจ๋ฐ”์ผ ์›น ์ฃผ์†Œ์ฐฝ ๊ฐ์ถ”๊ธฐ tip

    ๋ชจ๋ฐ”์ผํ™ˆํŽ˜์ด์ง€๋ฅผ ์ œ์ž‘ํ•  ๋•Œ ์ฝ”๋”ฉ์—์„œ ์œ„์˜ ์‚ฌ์ง„์ฒ˜๋Ÿผ ๋ชจ๋ฐ”์ผํ™ˆํŽ˜์ด์ง€ ์ฃผ์†Œ์ฐฝ์ด ์‚ฌ๋ผ์ง€๊ฒŒ๋” ํ•˜๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•œ ์„ค๋ช…์ด๋‹ค.

    ๋ณดํ†ต ํ”ํžˆ ์•„๋ž˜์™€ ๊ฐ™์€ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๋ฅผ ๋งŽ์ด ์“ด๋‹ค.

     

    window.addEventListener('load',function(){
    setTimeout(scrollTo,0,0,1);
    },false);

    ์ด ์Šคํฌ๋ฆฝํŠธ๋Š” ๋ชจ๋ฐ”์ผํ™ˆํŽ˜์ด์ง€์—์„œ ์ฃผ์†Œ์ฐฝ์ด ์‚ฌ๋ผ์ง€๋Š” ๊ธฐ๋Šฅ์„ ์ ์šฉํ•˜๊ณ  ์žˆ๋‹ค.

    ํ˜น์€ ์•„์˜ˆ body ํƒœ๊ทธ์— onload๋กœ ๋„ฃ์„ ์ˆ˜ ์žˆ๋‹ค.

    <body onload="setTimeout(function() {window.scrollTo(0, 1)}, 100)">
    ...
    </body>

    ์ด ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๋Š” window.setTimeout(func, delay, [param1, param2, ...])์„ ํ˜ธ์ถœํ•˜๋Š” ํ˜•์‹์ด๋‹ค.

    1. 0์ดˆ ํ›„์— scrollTo ๋ฉ”์†Œ๋“œ๋ฅผ ์‹คํ–‰์‹œ์ผœ๋ผ

    2. [param1, param2, ...] ์€ scrollTo ๋ฉ”์†Œ๋“œ์˜ ํŒŒ๋ผ๋ฏธํ„ฐ ๊ฐ’ (๊ฐ€๋กœ ์ขŒํ‘œ์œ„์น˜๊ฐ’ , ์„ธ๋กœ ์ขŒํ‘œ์œ„์น˜๊ฐ’)

    !์ฃผ์˜: ์„ธ๋กœ๋ฐฉํ–ฅ์˜ ์ปจํ…์ธ ๊ฐ€ ์ ์–ด์„œ ๋†’์ด๊ฐ€ ๋””๋ฐ”์ด์Šค ํ™”๋ฉด์˜ ๋†’์ด๋ณด๋‹ค ์ž‘์œผ๋ฉด ์ฃผ์†Œ์ฐฝ์ด ๋ฐ€๋ ค์˜ฌ๋ผ๊ฐ€์ง€ ์•Š์•„์„œ ์‚ฌ๋ผ์ง€์ง€ ์•Š๋Š”๋‹ค.

    ์ด๋Ÿด๊ฒฝ์šฐ <style> ํƒœ๊ทธ์— ์•„๋ž˜์™€ ๊ฐ™์€ portrait, landscape์˜ ๋ฏธ๋‹ˆ๋ฉˆ ๋†’์ด๋ฅผ ํ”ฝ์Šค์‹œํ‚จ๋‹ค.

    http://stackoverflow.com/questions/5855969/hide-address-bar-in-mobile-device-browser

    body { min-height:640px; }
    body[orient="portrait"] { min-height:640px; }
    body[orient="landscape"] { min-height:480px; }

    ์š”์ฆ˜ ๋‚˜์˜ค๋Š” ๋ชจ๋ฐ”์ผ ๋””๋ฐ”์ด์Šค๋“ค์˜ ํ•ด์ƒ๋„๊ฐ€ ๋†’์•„์กŒ๊ธฐ ๋•Œ๋ฌธ์— ๋ฐ˜๋“œ์‹œ ๋ทฐํฌํŠธ๋ฅผ ํ†ตํ•œ ๊ฐ€์ƒํ•ด์ƒ๋„๋ฅผ ํ™•์ธํ•ด์„œ ๊ฐ’์„ ์„ค์ •ํ•ด์ฃผ์–ด์•ผ ํ•œ๋‹ค.

    ๋ฐ˜๋ฉด์— ์•„์ดํฐ์ด ๊ฐ€๋กœ๋กœ ๋†“์ผ ๊ฒฝ์šฐ์—๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.

     

             addEventListener("load", function()    {         setTimeout(updateLayout, 0);     }, false);      var currentDeviceWidth = 0;         function updateLayout()     {         if (window.innerWidth != currentDeviceWidth         {             currentDeviceWidth = window.innerWidth;              var orient = currentDeviceWidth == 320 ? "profile" : "landscape";             document.body.setAttribute("orient", orient);             setTimeout(function()             {                 window.scrollTo(0, 1);             }, 100);                     }     }      setInterval(updateLayout, 400);     

     

     

    ๋ฐ˜์‘ํ˜•

    ๋Œ“๊ธ€