iPhoneã§javascriptã°ãªã°ãªã®ãi4Uãã®æè¡çãªè©±
1ã¶æã»ã©ã¾ã§ã«iPhoneã®safariã§ã©ãã¾ã§ãªãããªãµã¼ãã¹ãä½ããã®ãã試ãã¦ã¿ããã¦ã女ã®åç»åããã¯ãã¼ã¯ãµã¼ãã¹ã4Uãã®iPhoneç¨ãã¥ã¼ã¢ãä½ã£ã¦ã¿ã¾ããã
ãã®ãµã¼ãã¹ãæ±ã£ã¦ããã³ã³ãã³ããæé«ãªã®ã¯å¿è«ãªã®ã§ãããsafariã§ãªãããªã¤ã³ã¿ã¼ãã§ã¼ã¹ãå®ç¾ããããã«ä½¿ã£ã¦ãããã¯ããã¯ããªããªãé¢ç½ããã¨ãããè¦å´ã®çµæ¶ãªã®ã§ã¨ãããã解説ç¨ã®è¨äºãæ¸ãã¦ãããã¨æãã
iPhoneç¨ã®webãµã¤ããä½ããã¨ããã¨iui.jsã¨ã使ãã®ãå¤ãã¿ããã§ãããããã ã¨ã¢ããªã£ã½ãã¤ã³ã¿ã¼ãã§ã¼ã¹ã«ãªãã®ã§ãæããã¦ãµã¤ãã¨ãã¦ä½¿ããããã®ãã¯çåã§ãã
ç»åã®ãã¥ã¼ã¢ã¨ãã¦ã¯æ¬¡ã ã¨ã¹ã©ã¤ãã·ã§ã¼ã§ããã®ããããªã¨æãããiPhoneããããåºãã¨ãããæã§ã¹ã¯ãã¼ã«ãããªããé²è¦§ã§ããã®ããã¹ãã ã¨èãã¾ããã
ããã§åèã¨ãªã£ããµã¤ãã
ã§ããåºæ¬çãªæä½ã§ãjavascriptã§ã¿ããã¤ãã³ããåå¾ããé¨åã¯ä¸ã®ãµã¤ããåèã«ãã¾ããããã®ãµã¤ãã§ã¯ã¢ãã¡ã¼ã·ã§ã³ã®åä½ã«css3ã®æ©è½ã使ã£ã¦ãã¦ããèªä½ã¯å¤§å¤ã¹ã ã¼ãºã«åä½ãã¦ç¾ããã®ã§ãããä¸æä¸æ次ã«é²ãã§ããã¨ããåããæ°ã«å ¥ããå¤å°æç´ããããã¨ã«ãã¾ããã
éçºæã«æå¾ ãããã¤ã³ã
- æã§ã¹ã¯ãã¼ã«ãããæã®å¼·å¼±ã§ç»åã¹ã©ã¤ãã®é度ãå¤ãã
- ã¹ã ã¼ãºãªã¹ã¯ãã¼ã«ã»ç»åã®ãã¼ã
- ãã¼ã¸ã®é·ç§»ãçºçããªãããã«ãã
ã¯ããä¸è¨ã®ãµã¤ããåèã«css3ã®ã¢ãã¡ã¼ã·ã§ã³ãã«ã¹ã¿ãã¤ãºãã¦æã§ç¾è¡ã¨åããããªã¹ã¯ãã¼ã«ãå®è£ ãããã¨ããã®ã§ãããcss3ãé£ãããã¨ã¨æ°åããªç§åä½ã§cssã®ãã©ã¡ã¼ã¿ã®å¤ãå¤ãããã¨ããã®ã§ãµã¤ãå ¨ä½ãéãã¹ã ã¼ãºãªã¢ãã¡ã¼ã·ã§ã³ã¨ã¯ããã¾ããã§ããã
ããã§javascriptã«ããã¢ãã¡ã¼ã·ã§ã³ã§å®è£
ãããã¨ã«ãã¾ãããjsã§ã¢ãã¡ã¼ã·ã§ã³ã¨ãªãã¨tweeenerã¨ãã©ã¤ãã©ãªãããã¾ãããããããiphoneã®safariä¸ã§åä½ãããã«ã¯éããã¨ã¨ãç§ãå®è£
ãããåãã¨ãªãã¨èªç±åº¦ã«åé¡ãããã¾ãããçµå±ã¢ãã¡ã¼ã·ã§ã³ã®é¨åã¯èªåã§å®è£
ãã¾ããããããçµå±ã·ã³ãã«ã§ã¹ã¯ãªããã軽ãæå¾
ã®åä½ã«ç¹åã§ããã®ã§è¯ãã£ãã§ããã
//documentå ¨ä½ã«ã¤ãã³ããå¼µãã¨ãªã³ã¯ã®ã¯ãªãã¯ãåºæ¥ãªããªãã®ã§ãç»åã®é¨åã ãã«ã¤ãã³ããã»ãããã document.getElementById("container").addEventListener('touchstart', touchHandler, false); document.getElementById("container").addEventListener('touchmove', touchHandler, false); document.getElementById("container").addEventListener('touchend', touchHandler, false); document.getElementById("container").addEventListener('touchcancel', touchHandler, false);
ã¹ã ã¼ãºãªã¹ã¯ãã¼ã«ãå®æ½ããã®ãè¦å´ãã¾ãããåæã«ããããã®domãªãã¸ã§ã¯ãã®ã¹ã¿ã¤ã«ãå¤æ´ãããã¨ããï¼ä»åã®å ´åxæ¹åã®åº§æ¨ï¼ã¨ããã ãéããªãã¾ããä»åã®ãµã¼ãã¹ã¯æ¨ªã«é·ãã¹ã¯ãã¼ã«ã§ããã®ã§å¤ãã®ç»åãåæã«ã¹ã¯ãã¼ã«ããã¦ããããã«è¦ãã¾ãããåæã«åãã¦ãããªãã¸ã§ã¯ãã¯ï¼ã¤ã§ããä»ç»é¢ä¸ã«ãããã®ã¨ãã®åå¾ã®ç»åã ããã¦ã¼ã¶ã®æä½ã«ãã£ã¦åãã¾ãããã以å¤ã®ãã®ã¯ãç»é¢ã®è¦ããªãé¨åã«æ¾ç½®ããã¦ãã¾ããå·»ç©ã¿ãããªæãã«ä»è¦ãã¦ããé¨åã ããè¦ãã¦ãã¦ãä»ã®é¨åã¯æãããã¾ãã¦ãã¾ãã
ããããèããã¨ãåæã«ï¼æã ãã§ãããããã§ãã
ç»åã®ãã¼ãã£ã³ã°ã«ã¤ãã¦ã¯ãã¦ã¼ã¶ãè¦ããã¨ããç¬éã«ãã¼ãã£ã³ã°ï¼createï¼ãããããã«ãã¦ãã¾ããã¹ã¯ãªããçã«ã¯åå¾ãããã¨ããelementãç¡ãã£ããhtmlãçæãã¦å¼µãä»ãããè²¼ãä»ããããç¬éã«ç»åãçæãããã¨ããåç´ãªä»çµã¿ã§ããç¹ã«é«åº¦ãªç®¡çã¯ãã¦ãã¾ããããã·ã³ãã«ã§ããã¹ã¯ãªããçã«ãç°¡æ½ã§è¯ãæãã§ãã
iPhone.image.prototype.x = function(){ if(!this.elm)this.create();//ç»åã移åããããã¨ããã®ã«ãã®ã¨ã¬ã¡ã³ããç¡ãã£ãã®ã§ä½ãã if(arguments.length > 0){ var p = arguments[0]; this.elm.css('left',(p - 160) + "px"); }else{ var left = parseInt(this.elm.css('left')); return left + 160; } }
ç»åã®ãªã¹ãã¯ï¼ï¼æãã¨ã«ãµã¼ãã«åãåããã¦ãã¾ããã¬ã¹ãã³ã¹ãè¿ã£ã¦ãããããã¾ã§ã®ãªã¹ãã«è¿½å ãå¾ã¯åæ§ã«åä½ãã¾ãããã®ãããã®ãã¼ã¿ã®ç®¡çæ¹æ³ãé¢ç½ãã®ã§ãããã¹ã¯ãªãããè¦ã¦ããã ããã°ã¨ãããã¾ãã
javascriptã®ã©ã¤ãã©ãªã¨ãã¦jqueryãå©ç¨ãã¦ããã®ã§ãããããã¯ããã ãã¾ãããããã®ã©ã¤ãã©ãªã®èªã¿è¾¼ã¿ãç¡ããªãã°ãã£ã¨è»½ããªãããããã¾ããã
ãã®ä»ã®Tips
//ã¢ãã¡ã¼ã·ã§ã³ãããã¤ãã³ããæ±ãå ´åã¯ä¸è¨ã®ãããªè¨å®ããå§ã <meta name="viewport" content="width=device-width; initial-scale=1.0; minimum-scale=1.0; maximum-scale=1.0; user-scalable=0;" /> //ä¸ã®ã¢ãã¬ã¹ãã¼ãæ¶ãæ¹æ³ window.onload = function(){ setTimeout(scrollTo,500,0,1); }