'모바일/JAVAScript& jQuery'에 해당되는 글 5건

  1. 2011.03.08 Basic jQuery touchmove Event Setup
  2. 2011.03.08 Javascript Touch & Gesture Event for Mobile Browser 1
  3. 2011.03.04 아이폰 사파리용 웹 어플 개발하기
  4. 2011.03.04 모바일 사이트 버튼눌림효과 주기
  5. 2011.03.04 아이폰(iphone) safari 웹개발 기본 팁

Basic jQuery touchmove Event Setup

모바일/JAVAScript& jQuery 2011. 3. 8. 15:24

Basic jQuery touchmove Event Setup

I was recently tasked with replicating a “mousemove()” event on the iPad using the “touchmove()” event. I ran into a few snags and felt it was worthy enough to document my findings.

Here is the basic setup for using the “touchmove()” event:

$('#someElm').bind('touchmove',function(e){
      e.preventDefault();
      //CODE GOES HERE
});

Nothing really different about the setup behind the “touchmove()” event and any other native jQuery event. The only difference is that when using a “touchmove()”, you must always start your event handler with a event preventDefault();.

Next, its important to point out that if our script is ran as is, you will run into some issues with events being sent to your touch handlers, and none of them having whats called “e.touches” or “e.changedTouches” properties.

“After deep debugging, I eventually discovered that the source of this problem was the fixmethod in jquery’s event code. The fix method tries to copy the event object in order to fix various cross browser issues. Unfortunately, it seems that mobile safari does not allow the e.touchesand e.changedTouches properties on event objects to be copied to another object. This is weird and annoying. Luckily you can get around this issue by using e.originalEvent.” -  http://www.the-xavi.com/articles/trouble-with-touch-events-jquery

So to fix our issue we can simply create a new “touch” variable, then condition both “.originalEvent” and “.changedTouches” to this variable, like so:

$('#someElm').bind('touchmove',function(e){
      e.preventDefault();
      var touch = e.originalEvent.touches[0] || e.originalEvent.changedTouches[0];
      //CODE GOES HERE
      console.log(touch.pageY+' '+touch.pageX);
});

I included a little console.log() demo showing how you could test your “touchmove()” event coordinates.

The Problem:

There is one slight problem (depending on your functionality needs) when using this “touchmove()”. The event continues to fire even when your “touch” has moved out side the element.

So in other words, it seems that once the event has started, it’s no longer confined to the element its being assigned to.

The Fix:

There is no real solid fix for this issue yet, however you can band-aid the issue with a little math.

Basically, by trimming the elements top and left offset from both of the touchmove’s x and y event coordinates. You can then condition these trimmed values against both the elements width and height (respectively of course).

Completed touchmove() Event with jQuery with Confined Fix:

$('#someElm').bind('touchmove',function(e){
      e.preventDefault();
      var touch = e.originalEvent.touches[0] || e.originalEvent.changedTouches[0];
      var elm = $(this).offset();
      var x = touch.pageX - elm.left;
      var y = touch.pageY - elm.top;
      if(x < $(this).width() && x > 0){
	      if(y < $(this).height() && y > 0){
                  //CODE GOES HERE
                  console.log(touch.pageY+' '+touch.pageX);
	      }
      }
});

Vole! No matter where the location of the element to the page, or the width and height of the element, the event will only be fired in side of the element.

And that’s your basic setup for a “touchmove()” event using jQuery alone.

Have fun.


출처 - http://www.devinrolsen.com/basic-jquery-touchmove-event-setup/

:

Javascript Touch & Gesture Event for Mobile Browser

모바일/JAVAScript& jQuery 2011. 3. 8. 13:04

모바일 브라우저의 Touch, Gesture Event 처리 방법에 대해서 정리해봅니다.
다른 여러 사이트에서 아이폰에대해서는 정리가 많이 되었던데요... 
저는 http://backtothecode.blogspot.com/2009/10/javascript-touch-and-gesture-events.html 이 블로그를 참조하여 아이폰과 안드로이드 폰에 대해서 함께 정리하여 봅니다.


Android and iPhone touch events

Android, iPhone은 공통적으로 터치와 관련해서 다음과 같은 이벤트를 제공합니다. 
  • touchstart - mouseDown 이벤트와 비슷한 이벤트로 손이 화면에 닿으면 발생
  • touchmove - mouseMove 이벤트와 비슷한 이벤트로 손 터치한 상태로 이동하면 발생
  • touchend - mouseUp 이벤트와 비슷한 이벤트로 손을 화면에서 뗄때 발생. 아이폰의 경우 touchcancel 이벤트가발생
  • touchcancel - bit of a mystery 라고 표현하네요. 쬐금 이상하다는...

예제)
document.addEventListener('touchstart', function(event) {
    alert
(event.touches.length);
}, false);

Event object
위의 예제에서 보듯이 Touch Event Object는 touches array를 포함하고 있다.
안드로이드의 경우 이벤트에는 한개의 터치 오브젝트를 포함한다. 즉 touches.length는 1이다.
터치 아이폰의 경우에는 멀티터치가 가능하기 때문에 touches array를 통해서 핸들링 할 수 있다. 
터치 이벤트 객체는 마우스 이벤트 객체와 같이 pageX, pageY 등의 값들을 포함하고 있다.

예제 )
document.addEventListener('touchmove', function(event) {
   
event.preventDefault();
   
var touch = event.touches[0];
    console
.log("Touch x:" + touch.pageX + ", y:" + touch.pageY);
}, false);

  • clientX: X coordinate of touch relative to the viewport (excludes scroll offset)
  • clientY: Y coordinate of touch relative to the viewport (excludes scroll offset)
  • screenX: Relative to the screen
  • screenY: Relative to the screen
  • pageX: Relative to the full page (includes scrolling)
  • pageY: Relative to the full page (includes scrolling)
  • target: Node the touch event originated from
  • identifier: An identifying number, unique to each touch event

iPhone Touch and Gesture Events

애플의 WebKit은 안드로이드와 달리 몇가지 것들을 추가적으로 지원한다. touchEnd 이벤트는 event.touches array에서 현재 touch 를 제거해준다. 대신 event.changeTouches array를 이용해서 볼 수 있다.

애플 iPhone의 터치 이벤트 객체
  • touches - touchStart, touchMove, touchEnd 의 터치 정보를 포함하고 있는 array
  • targetTouches - 같은 target Element로부터 비롯된 touches 정보를 포함
  • changedTouches - 모든 touch 정보를 가지고 있는 객체


Gesture events

애플에서는 pinching, rotating과 같은 멀티 터치 이벤트를 처리할 수 있도록 지원한다.
  • gesturestart - 멀티 터치 시작
  • gesturechange - 멀티 터치를 해서 움직일 때 발생
  • gestureend - 멀티 터치 이벤트가 끝날때 발생
멀티 터치를 위한 이벤트 객체는scale, rotation 값을 갖고 touch 객체가 없다.

예제 )
document.addEventListener('gesturechange', function(event) {
   
event.preventDefault();
    console
.log("Scale: " + event.scale + ", Rotation: " + event.rotation);
}, false);

Event table

touchstart
touchmove
touchend
gesturestart
gesturemove
gestureend
Android
y
y
y
n
n
n
iPhone
y
y
y
y
y
y
has event.touches
y
y
y
n
n
n
(iPhone) has event.scale and event.rotation
n
n
n
y
y
y
(iPhone) touch in event.touches
y
y
n
-
-
-
(iPhone) touch in event.changedTouches
y
y
y
-
-
-




※ 참고 Link :

출처 - http://blog.hometown.co.kr/tag/touchmove
:

아이폰 사파리용 웹 어플 개발하기

모바일/JAVAScript& jQuery 2011. 3. 4. 14:41

아이폰 사파리에서 아이폰 어플인양 돌아가는 페이지를 만들어보자~!

 

  1. 아이폰에서 사용중인 브라우저(모바일 사파리)는 Webkit엔진 기반의 브라우져 이다. 안드로이드 브라우저도 Webkit기반이므로 지금 포스팅 하는 내용은 안드로이드 개발시에도 유용하게 사용할 수 있다.
  2. meta정보로 페이지 사이즈를 조절하게 되는데 "viewport"를 이용하면 아이폰 사이즈에 딱맞는 페이지로 로드 된다.
     <meta name="viewport" content="height=device-height; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;" />

     

  3. 모바일 사파리(아이폰)에서 어플처럼 아이콘 등록 할 수 있도록 처리 하는 방법이다.

     <meta name="apple-mobile-web-app-capable" content="yes" /> 

  4. 스테이터스 바 없애는 방법이라고 하는데 안없어진다 (-_-;)

      <meta name="apple-mobile-web-app-status-bar-style" content="black" />

  5. 사파리 브라우져의 특성상 주소창이 위에 항상 보이게 되는데 이걸 없앨 수는 없지만 페이지 로드시 스크롤 하는 방법으로 안보이게 처리 할 수 있다.

      function hideURLbar(){
            window.scrollTo(0, 1);
        }

  6. PC에서는 마우스를 사용하고 아이폰에서는 터치를 사용하는 인터페이스 차이로 인해 이벤트가 전혀 다르게 동작하는 경우가 있다. 예를 들면 Drag & drop같은 이벤트의 경우 아이폰은 TouchStart, TouchMove, TouchEnd 이벤트를 이용하는데 이것은 아이폰 기본 기능에 페이지 드래그가 할당되어있기때문에 드래그 되지 않도록 막아야 HTML Dom Object 드래그가 가능해진다. 아래와 같이 이벤트를 막자!

    <script type="text/javascript">  

    function touchHandler(event)
     {
         var touches = event.changedTouches,
             first = touches[0],
             type = "";
            
        
         switch(event.type)
         {
             case "touchstart":
                 type = "mousedown";
                 break;
                
             case "touchmove":
                 type="mousemove";       
                 event.preventDefault();
                 break;       
                
             case "touchend":
                 type="mouseup";
                 break;
                
             default:
                 return;
         }
        
        
         var simulatedEvent = document.createEvent("MouseEvent");
         
            
         simulatedEvent.initMouseEvent(type, true, true, window, 1, first.screenX, first.screenY, first.clientX, first.clientY,
                                       false, false, false, false, 0/*left*/, null);
                                                                                
         first.target.dispatchEvent(simulatedEvent);
      
        }
     
     function init()
     {
         document.addEventListener("touchstart", touchHandler, false);
         document.addEventListener("touchmove", touchHandler, false);
         document.addEventListener("touchend", touchHandler, false);
         document.addEventListener("touchcancel", touchHandler, false);   
     }

     

    document.body.onload = init;

    </script>

 

:

모바일 사이트 버튼눌림효과 주기

모바일/JAVAScript& jQuery 2011. 3. 4. 14:30


HTML :

<a class="btn">Touch button</a>

CSS :

.btn {
text-indent-9999px;
displayblock;
width200px/* 버튼 넓이 */
height50px/* 버튼 높이 */
backgroundtransparent url(img/button.png) no-repeat;
}
.btn:active {
backgroundtransparent url(img/button_press.png) no-repeat;
}


JS(jQuery) :

$(document).ready(function() {
   $('.btn').live('touchstart',function(event){
        $(this).addClass('active');
    });
    $('.btn').live('touchend',function(event){
        $(this).removeClass('active');
    });
});


 [출처] 모바일 사이트 버튼눌림효과 주기|작성자 리베하얀  

:

아이폰(iphone) safari 웹개발 기본 팁

모바일/JAVAScript& jQuery 2011. 3. 4. 13:20

아이폰(iphone) safari 웹개발 기본 팁

 

1. -webkit-text-size-adjust

페이지가 회전할때 폰트사이즈가 자동으로 변경되지 않도록 한다 그러나 안좋은 면이 있는데 보통 webkit 브라우저들에서는 적용안됨.

 

auto : default값, 화면의 폭에 맞추어서 텍스트 크기가 자동으로 조절된다.

none : 폰트의 자동크기변환을 막으며 모바일웹에서 일반적으로 설정한다.

n% : 폰트크기를 지정된 사이즈로 변경한다.

 

 html {

      -webkit-text-size-adjust:none;

  }

 
2. apple-mobile-web-app-capable

<meta name="apple-mobile-web-app-capable" content="yes">

content값이 yes로 지정하면 풀스크린모드로 자동하고 그렇지 않으면 일반모드로 작동한다.

window.navigator.standalone의 속성을 사용해서 풀스크린모드를 표시할수 있다.

content : yes|no

 

iphone os 2.1 이상

 

3. apple-mobile-web-app-status-bar-style

<meta name="apple-mobile-web-app-status-bar-style" content="black">

content : black | black-translucent | default

 

iphone os 2.1 이상

 

4. format-detection

<meta name="format-detection" content="telephone=no">

content : default | no

전화번호형식의 경우 자동으로 전화걸기로 연결되는데 no로 할 경우 불가능하도록 한다.

 

iphone os 1.0 이상

 

5. viewport

<meta name="viewport" content="width=320, initial-scale=2.3, user-scalable=no">

content : width [number | device-width], height [number | device-height], initial-scale [number], user-scalable [no | yes]

width : default 980, 범위 200 ~10,000 (숫자로 입력) 픽셀로 표시됨

height : width값에 따라 비유로 적용이 됨, 범위 223 ~ 10,000 (숫자로 입력) 픽셀로 표시됨

initial-scale : 웹페이지가 보일 때 최초 한번 적용되어서 보이는 비율, zoom in에 대한 범위를 다음 속성으로 지정할수 있다.

minimum-scale : default 0.25, 범위 0 ~ 10.0

maximun-scale : default 1.6, 범위 0 ~ 10.0

user-scalable : yes | no (no 속성은 스크롤 할때 input box에 enter가 입력 되는 것을 막음.

device-width : 기기 width 픽셀값

device-height : 기기 height 픽셀값

 

7.iphone safari Apple Touch Icon표시

Apple "favicon" 표시방법(WebClip Bookmark)

이미지 파일 사이즈 : 57 * 57

<link rel="apple-touch-icon" href=http://madebysquad.com/iphone/icon.png />

 

8.아이폰에서 동영상 재생은 MP4파일로 링크
오페라 같은경우 아래와 할경우 파일이 다운이 됨. 옴니아2에서도 동작은 함.

    아이폰에서는 약간의 딜레이(곰티비, 다음TV팟 모두 그렇듯)를 거치면 영상이 아주 잘 재생됩니다.

 

<A HREF="AAAA.mp4"> 동영상보기 </A>

 

9.가장 상위 오브젝트는 수치로 가로를 넣어줘야함.

ex>  <div style="width=100%;">  --->   <div style="width=480px;">

 

10.작은 모바일 화면에 맞게 웹페이지 화면 맞추기

META 태그를 쓰면  화면이 모바일 화면에 딱 맞춰서 확대되어 보이게 됩니다.
다른 플랫폼은 모르겠고 아이폰 같은 경우는 가로가 480px 이라 생각해서 화면을 맞추면 되더군요

<meta name="viewport" content="user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, width=device-width" />

 width=device-width
이 값은 페이지를 기기의 width에 맞도록 출력합니다. 아이폰은 320*480의 세로보기 모드와 480*320의 가로보기 모드를 가지고 있습니다. width=780 과 같이 특정 값을 정의할 수도 있지만, 가로, 세로보기 모드에 최적화 시키기 위해서 width=device-width로 설정하는 경우 기기의 width값에 맞춰서 페이지를 보여줍니다.

initial-scale=1.0
이것은 페이지가 로딩될때 확대비율을 정할수 있습니다. 값이 커질 수록 확대 비율된 모습으로 페이지가 나타납니다.

maximum-scale=1.0
허용가능한 확대비율의 최대치를 설정합니다.

user-scalable=0
사용자의 확대보기를 허용할지 여부를 설정합니다. 값은 0(허용하지 않음), 1(확대보기 허용함) 입니다.

 

11.모바일로 홈페이지 접속하는 사람들만 골라서 모바일홈페이지로이동시켜주기

 

 

 

12.모바일 사파리의 inputtype에 따른 키보드 레이아웃변화

 

1. <input type='text' /> 기본 텍스트 타입 입니다.

따로 변경된 부분은 없는 일반 적인 키보드 레이아웃이며 Form 요소로서 return 부분의 Text만 Go 로 변경됬습니다.




 
2. <input type='search' /> search 타입 입니다. 
기본 text type과 동일하며 return 부분의 Text만 Search 로 변경됬습니다. Form 의 내부에 있을때만 적용됩니다.





3. <input type='tel' /> tel 타입 입니다. 
제일 특이한 부분인데요 전화번호를 입력하기 위한 숫자 키보드가 나타납니다.





4. <input type='url' /> url 타입 입니다. 
url 입력시 사용자 편의를 위해 하단에 "." , "/"  , ".com" 등의 국가코드에 대한 알리아스를 제공합니다. ".com" 버튼을 길게 탭하고 있으면 선택할수 있는 리스트가 나타납니다.






5. <input type='email' /> email 을 입력할수 있는 type 입니다. 
위의 url 과 동일하세 입력편의를 위한, "@" , "." 을 기본 레이아웃으로 제공하여 줍니다.





6. <input type='password' /> 일반적으로 많이 쓰이는 password 타입입니다.
텍스트를 타이핑하면, 숨김문자로 표시됩니다. 한가지 단점으로, 영문키보드만 사용가능합니다.





7. <input type='number' /> 마지막으로 숫자 입력을위한 number 타입입니다.
이때 나타나는 레이아웃은 일반 키보드 레이아웃에서 "123" 숫자 키를 선택했을떄 나타나는 레이아웃과 동일합니다.

 

8.사파리에서 검색에 히스토리 아이콘 표시하는 방법

<input type="text" />

사파리에서 검색에 히스토리 아이콘 표시하는 방법

 

<input type="search" results="5" />

다음 브라우저에서는 text field로 표시가 되는 것을 확인하였다고 하네요

Safari

Camino

Firefox

IE6

IE7

Opera 9

 

그러나 유효하지 않는 XHTML이 되버려서 safari만을 위한 자바스크립트를 사용하는 것이 더 좋을 것 같다.

스크립트 많이 쓰이는 구만...

 

safari ->사파리 브라우저 확인용 변수 사용자가 정의를 해야 되겠군요.

if (safari) {

  var s = $("#s"); // s라는 ID값을 가진 객체를 jquery로 선택

  s.attr("type", "search").attr("results", "5");

}

 

if (safari) {

  var s = document.getElementById("s");

  s.type = "search";

  s.setAttribute("results", "5");

}

  

13.아이폰 모바일 사파리에서 아이폰 기본어플 실행하기
1. 전화걸기
Anchor 태그에 "tel" 프로토콜을 사용하면 자동으로 전화 연결이 됩니다. 전화 기능이 없는 아이팟 터치 에서는 주소록에 등록하기 메뉴가 뜹니다. 또한 '&lt meta name = "format-detection" content = "telephone=no &gt' 태그 설정을 해주지 않으면 연속 되는 7자리 이상의 숫자나 특정 패턴의 숫자는 전화번호로 인식하기 때문에 주의 하여야 합니다.

<a href="tel:15880010">Show 고객센터 연결하기</a>


2. 문자보내기
Anchor 태그에 "sms"  프로토콜을 사용하면 문자보내기로 연결됩니다.
문자 보내기 어플은 아래와 같이 전화번호를 입력하여 받는사람을 지정할수 있습니다.

<a href="sms:">문자보내기 어플실행</a>
<a href="sms:1588-0010">Show 고객센터에 문자보내기 </a>


3. 메일보내기
Anchor 태그에 "mailto"  프로토콜을 사용하여 메일을 보낼수있습니다. 이는 모바일 사파리 뿐만 아니라 모든 브라우져에서 공통된 기능이구요, mailto 에는 받는사람, 메일제목, 참조자, 메일 내용까지 지정하여 어플을 실행시킬수 있습니다.
또한 메일보내기는 사파리를 종료하지 않고 메일보내기가 실행되므로, 사용자 관점에서는 참유용한 기능인듯 합니다.

mailto 에서사용 가능한 속성은 아래와 같습니다.
cc : 참조
bcc : 숨은 참조
subject : 메일제목
body : 메일본문

<a href="mailto:">메일보내기 실행</a>
<a href="mailto:sgb000@hanmail.net">bongdal 에게 메일보내기</a>
<a href="mailto:sgb000@hanmail.net?cc=sgb000@naver.com&bcc=sgb000@nate.com&subject=mailto test&body=mail send body">내용채워서 메일보내기</a>


4. 지도 어플 실행하기
조금 특이한 부분으로 애플과 구글의 제휴로 인해 실행되는부분인듯합니다.
그냥 Anchor 태그에 구글맵 주소를 입력하면 자동으로 구글 지도 어플을 실행시킵니다.


<a href="http://maps.google.com/maps?q=seoul&z=5">서울지도보기</a>
<a href="http://maps.google.com/maps?daddr=seoul&saddr=busan">서울-부산 길찾기</a>

Google Maps parameters
Table 1  Supported Google Maps parameters

Parameter

Notes

q=

The query parameter. This parameter is treated as if it had been typed into the query box by the user on the maps.google.com page. q=* is not supported

near=

The location part of the query.

ll=

The latitude and longitude points (in decimal format, comma separated, and in that order) for the map center point.

sll=

The latitude and longitude points from which a business search should be performed.

spn=

The approximate latitude and longitude span.

sspn=

A custom latitude and longitude span format used by Google.

t=

The type of map to display.

z=

The zoom level.

saddr=

The source address, which is used when generating driving directions

daddr=

The destination address, which is used when generating driving directions.

latlng=

A custom ID format that Google uses for identifying businesses.

cid=

A custom ID format that Google uses for identifying businesses.



5. YouTubu 어플 실행하기
역시, Anchor 에서 youtube와 연결된 링크가 있을경우 자동으로 내장된 YouTubu 어플이 실행됩니다.
웹상에서는 위의경로는 웹페이지에서 실행되며, 아래의 경로는 전체화면 플레이어가 실행됩니다.

<a href="http://www.youtube.com/watch?v=a_GaLdTbOG4">YouTube Play1</a>
<a href="http://www.youtube.com/v/a_GaLdTbOG4">YouTube Play2</a>



6. 아이튠즈 및 앱스토어 실행하기
아래의 URL로 앱스토어 및 아이튠즈 어플이 실행가능합니다.
한가지 주의 할점은 앱스토어의 경우 "http://itunes.apple.com/kr/app/id304608425?mt=8" 어플이 일반적인 경로(일반 web에서 사용)이나, 모바일 사파리에선 내부에서 자동으로 아래 패턴으로 변경하여 사용합니다. 하지만 어플위에 올라간 UIWebview 컨트롤상에서는 따로 구현해주지 않으면 앱스토어 넘어가지 않습니다.


<a href="http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=304608425&cc=kr&mt=8&ign-iphone=1 ">지도어플(앱스토어 연결)</a>
<a href="http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewAlbum?i=156093464&id=156093462&s=143441">Toy Story OST(itunes 연결)</a>
 
 
14.모바일 사파리에서 Geolocation 사용하기

Geolocation 객체는 모바일 사파리에서 위치 정보를 담고 있는 오브젝트로 OS3.0 이상에서 사용가능하며.
좌표체게는 위도와 경도를 이용하는 WGS84 좌표계를 쓰고 있다.

"위치 정보는 확률적 추정에 의한 것으로 정확성을 보장하지 않는다"(
FF3.5 위치정보 도움말)

<script type="text/javascript">
   /* Mobile Browser UA 체크 */
   var ua = navigator.userAgent.toLowerCase();
    browser = {
                skt : /msie/.test( ua ) && /nate/.test( ua ),
                lgt : /msie/.test( ua ) && /([010|011|016|017|018|019]{3}\d{3,4}\d{4}$)/.test( ua ),
                opera : /opera/.test( ua ) || /opera mobi/.test( ua ),
                ipod : /webkit/.test( ua ) && /\(ipod/.test( ua ) ,
                iphone : /webkit/.test( ua ) && (/\(iphone/.test( ua ) || /\(device/.test( ua )),
                android : /webkit/.test( ua ) && /android/.test( ua )
    }

  /* OS version 체크 */
<PRE class=code-javascript>var version = (function(){
var retObj = {}
if(browser.ipod || browser.iphone){
var pattern = /(iphone|ipod)+\s+os+\s+(\d)_(\d)(?:_(\d))?/igm
var result = pattern.exec(ua);

if(result != null && result.length > 0){
retObj.versionFull = result[0];
retObj.os = result[1];
retObj.major = result[2];
retObj.minor = result[3];
retObj.build = result[4] ? result[4] : 0;
}
}

return retObj;
})()</PRE>

// 3.1.2 에서는 Geolocation이 제대로 동작하지 않음.
if((browser.ipod || browser.iphone) && (version.major > 2 &&  version.build < 2)){
    navigator.geolocation.getCurrentPosition(foundLoc);
}

function foundLoc(position){
  var latitude = position.coords.latitude;
  var longitude = position.coords.longitude;
  alert("위도 : "+latitude +" , 경도 : "+longitude )
}

</script> 

 

16.기울기에 따라 css따로 불러오게 하기

 <script type="text/javascript">
  function orient()
  {
   switch(window.orientation){
     case 0: document.getElementById("orient_css").href = "css/iphone_portrait.css";
           break;

     case -90: document.getElementById("orient_css").href = "css/iphone_landscape.css";
        break;

     case 90: document.getElementById("orient_css").href = "css/iphone_landscape.css";
     break;

  }
 }
  window.onload = orient();

  </script>

 

 <body onorientationchange="orient();">

 </body>
 </html>

 

 

17.툴바 숨기기

사파리브라우저의 주소입력창과 검색창이 있는 툴바를 보이지 않는 상태로 변환합니다.
툴바가 사라지는 것이 아니라 스크립트를 통하여 스크롤을 아래로 내려 툴바 바로 아래에서부터 웹페이지가 보여질수 있도록 하는것입니다.
이 스크립트를 사용하는 경우 사용자에게 최초로 페이지를 보여줄때 툴바가 차지했던 부분까지 화면공간을 확보하여 보여줄 수 있습니다.

 <script type="text/javascript">

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

   }, false);

  </script>
 
 
18.콘텐츠 길이가 너무 짧아 툴바가 보여지지도 사라지지도 않은 반쯤 가려진 상태로 보이게 되는 경우
페이지 콘텐츠 길이가 너무 짧아서 스크롤할 내용이 없을때 이 스크립트는 우리가 원하는 기능을 수행하지 않을 수도 있습니다.
그리고 페이지 콘텐츠 길이가 스크롤을 내리기에 어정쩡한 길이라면 툴바가 보여지지도 사라지지도 않은 반쯤 가려진 상태로 보이게 되는 경우도 있습니다.
이런문제를 해결하기 위해서는 높이값을 최대사이즈로 지정하여 페이지가 스크롤될 수 있게 할 수 있습니다.
<meta name="viewport" content="height=device-height,width=device-width" />
 
19.라운드 박스
.box { 
   -webkit-border-radius: 5px;  /* safari */
   -moz-border-radius: 5px;  /* firefox */
   background: #ddd; 
   border: 1px solid #aaa; 
}
 
20.터치이벤트
touchstart
touchend
touchmove
touchcancel (시스템이 터치한 것을 취소하는 경우)


이벤트 발생시 event객체를 전달 받는데 다음과 같은 프로퍼티가 존재합니다.

touches : 복수로 화면에 터치되는 각 손가락들에 대한 터치 이벤트 모음들. 이 객체들은 페이지에 터치되는 좌표들의 값을 가지고 있습니다.
targetTouches : 터치할 때 발생합니다. 그러나 전체 페이지가 아닌 타깃 요소에만 반응합니다.


21. 제스쳐

gesturestart
gestureend
gesturechange

event 객체를 전달받으며 다음과 같은 프로퍼티가 존재합니다.

event.scale : 확대비율 값입니다. 값 1은 확대축소가 되지 않은 기본 상태 입니다. 값이 1보다 작을 때는 줌-아웃이며 줌-인일때는 1보다 값이 큽니다.
event.rotate - 회전 각도입니다.
 
22.기본 어플 호출하기
 

 - 전화걸기 : <a href="tel:1588-2120 ">블루웹 고객센터</a>

 - 문자보내기 : <a href="sms:010-0000-0000">문자보내기</a>
 - 문자보내기실행 : <a href="sms:">문자보내기</a>

 - 메일보내기실행 : <a href="mailto:">메일보내기</a>
 - 메일보내기 : <a href="mailto:echos@blueweb.co.kr">메일보내기</a>
 - 내용채워서 메일보내기 : <a href="mailto:echos@blueweb.co.kr?cc=echos@blueweb.co.kr&bcc=echos@blueweb.co.kr&subject=test subjct&body=test body"">메일보내기</a>



출처 - http://cafe.naver.com/republiccompany.cafe

: