Upgrade to Pro — share decks privately, control downloads, hide ads and more …

three.jsでレスポンシブ対応する

 three.jsでレスポンシブ対応する

kaidouji85

May 19, 2018
Tweet

More Decks by kaidouji85

Other Decks in Technology

Transcript

  1. ϝσΟΞΫΤϦͷྫ /* iPhone 6, 6S, 7, 8 (ϥϯυεέʔϓɺϙʔτϨʔτڞ༻) */ @media

    only screen and (min-device-width: 375px) and (max-device-width: 667px) and (-webkit-min-device-pixel-ratio: 2) { .content { color: red } } /* iPhone 5, 5S, 5C and 5SE (ϥϯυεέʔϓɺϙʔτϨʔτڞ༻) */ @media only screen and (min-device-width: 320px) and (max-device-width: 568px) and (-webkit-min-device-pixel-ratio: 2) { .content { color: blue; } }
  2. +4ϝσΟΞΫΤϦม׵ྫ if ( 375 <= screen.width && screen.width <= 667

    && window.devicePixelRatio === 2 ) { // σόΠεຖͷઃఆΛॻ͘ } @media only screen and (min-device-width: 375px) and (max-device-width: 667px) and (-webkit-min-device-pixel-ratio: 2) { .content { color: red } } +BWB4DSJQU ϝσΟΞΫΤϦ
  3. ΋ͬͱ؆୯ͳํ๏ // @flow /** ήʔδΛ౳ഒදࣔ͢ΔͨΊʹ࠷௿ݶඞཁͱͳΔը໘෯ */ const MIN_SCREEN_WIDTH = 524;

    /** * σόΠεʹԠͨ͡ήʔδܥήʔϜΦϒδΣΫτͷഒ཰Λฦ͢ * ϙʔτϨʔτɺϥϯυεέʔϓͰഒ཰Λม͑ΔΑ͏ͳ͜ͱ͸͠ͳ͍ * ϙʔτϨʔτͰը໘෯͕࠷௿ʹͳΔͱ૝ఆ͠ɺը໘෯͕ج४஋ʹຬͨͳ͍৔߹ʹ͸ॖখදࣔ͢Δ * * @return ഒ཰ */ export function getGaugeScale(): number { const portraitScreenWidth = Math.min(screen.width, screen.height); if (portraitScreenWidth <= MIN_SCREEN_WIDTH) { return portraitScreenWidth / MIN_SCREEN_WIDTH; } return 1; }
  4. 1FSTQFDUJWF$BNFSB // @flow import * as THREE from “three"; /**

    * ΢Πϯυ΢ϦαΠζʹԠͯ͡ɺPerspectiveCameraͷ֤छύϥϝʔλΛߋ৽͢Δ * ຊؔ਺ʹ͸෭࡞༻͕͋Δ * * @param camera ߋ৽ର৅ͷΧϝϥ */ export function onResizePerspectiveCamera(camera: THREE.PerspectiveCamera): void { camera.aspect = window.innerWidth / window.innerHeight; camera.updateProjectionMatrix(); }
  5. 0SUIPHSBQIJD$BNFSB // @flow import * as THREE from “three"; /**

    * ΢Πϯυ΢ϦαΠζʹԠͯ͡ɺOrthographicCameraͷ֤छύϥϝʔλΛߋ৽͢Δ * ຊؔ਺ʹ͸෭࡞༻͕͋Δ * * @param camera ߋ৽ର৅ͷΧϝϥ */ export function onResizeOrthographicCamera(camera: THREE.OrthographicCamera): void { camera.left = -window.innerWidth/2; camera.right = window.innerWidth/2; camera.top = window.innerHeight/2; camera.bottom = -window.innerHeight/2; camera.updateProjectionMatrix(); }
  6. Ϩϯμϥ // @flow import * as THREE from 'three'; /**

    * ϨϯμϥαΠζΛ΢Πϯυ΢αΠζʹ߹ΘͤΔ * ຊؔ਺ʹ͸෭࡞༻͕͋Δ * * @param render Ϩϯμϥ */ export function fitToWindowSize(render: THREE.WebGLRenderer) { render.setSize(window.innerWidth, window.innerHeight); }