야후 세계 지도 API 를 활용해서 지도를 만드는 비교적 간단한 샘플입니다. 아래 소개된 소스 코드를 실행하면 100개의 마커가 뿌려지고 해당 마커를 클릭하면 이미지를 보여주는 다음과 같은 실행 화면을 확인할 수 있습니다. 자신의 홈페이지에서 테스트 하기 위해서는 야후 거기 지도 오픈 API 키를 해당 홈페이지 (http://kr.open.gugi.yahoo.com/Regist/regist.php) 에서 얻을 수 있으며 키 값($yahoo_map_api_key)을 얻은 API 키로 교체해야 합니다. 참고로 구글 지도 API에도 관심이 있는 분은 앞서 소개한 "자바스크립트로 지도 만들기, 구글 지도 API 매시업(Mashup)" 포스트도 참고하세요.

[실행 화면] http://www.hompydesign.com/map/yahoo.html


[소스 코드]
<HTML>
<HEAD>
<TITLE><?=$hompy_title?></TITLE>
<script type="text/javascript" src="/js/jquery.js"></script>
<script type="text/javascript" src="http://kr.open.gugi.yahoo.com/Client/AjaxMap.php?v=3.7&appid=$yahoo_map_api_key"></script>
<style type="text/css">

#map_box {position:relative;}
#map_canvas { width: 578px; height: 460px; margin: 0; padding: 0; border: 0; }

#map_box {width:578px; border: 4px solid #cccccc; padding:2px;}
#display_loading_box {width:578px; height:460px; position:absolute; background-color:#000000; z-index:1000; opacity: 0.5; filter: alpha(opacity = 50);}
#display_loading_box_icon {margin: 214px 273px; width:32px; height:32px;}

body,td,tr { font-size:12px; font-family:돋움,verdana,arial,sans serif;}

.window_image {border:1px solid #cccccc; width:140px; height:100px; margin:6px;}

</style>
<script type='text/javascript'>
<!--

var map = null;
var current_lon = 127.046;
var current_lat = 37.5066;
var current_zoom = 14;
var person_list = [];

$(document).ready(function(){
      display_loading();
      map = new YMap($("#map_canvas")[0]);

      map.addTypeControl();
      map.addZoomLong();
      map.addPanControl();
      //map.drawZoomAndCenter(encodeURIComponent("강남역"), 4);
      map.drawZoomAndCenter(new YGeoPoint(current_lat,current_lon), 4);
      map.setMapType(YAHOO_MAP_REG);

      display_marker({user:0,lat:current_lat,lon:current_lon});
      for (record in person_list) {
            display_marker(person_list[record]);
      }
      setTimeout(display_loaded, 1000);
});

function display_loading(){
      var html = "<div id='display_loading_box'><img src='images/loading.gif' id='display_loading_box_icon' /></div>";
      $('#map_canvas').before(html);
}

function display_loaded(){
      $('#display_loading_box').remove();
}

function display_marker(record){
      with (record) {
            var point = new YGeoPoint(Number(lat),Number(lon));
            var marker = create_marker(point, user);
      }
      map.addOverlay(marker);
      //map.setCenter(point, current_zoom, G_NORMAL_MAP);
}

function create_marker(point, person) {
      var icon = new YImage();
      icon.src = 'images/pot.png';;
      icon.size = new YSize(36, 36);
      icon.offset.x = -18; icon.offset.y = 0;      

      var marker= new YMarker(point, icon);
      //marker.addAutoExpand("pos:"+person);
      var html = '<a href="http://hompy.info/583"><img src="/hompydesign.com?seq='+person+'" class="window_image"></a>';
      YEvent.Capture(marker, EventsList.MouseClick, function(){
            marker.openSmartWindow(html);
      });
      return marker;
}

person_list =
[{user:1,lon:127.034,lat:37.5059},{user:2,lon:127.029,lat:37.5125},{user:3,lon:127.032,lat:37.5306},{user:4,lon:127.034,lat:37.4994},{user:5,lon:127.036,lat:37.5169}];

-->
</script>
</HEAD>

<BODY>
<div id="map_box">
<div class="map" id="map_canvas"></div>
</div>
</BODY>
</HTML>

웹프로그래머의 홈페이지 정보 블로그 http://hompy.info/583

댓글을 달아 주세요

  1. 비밀방문자 2009/07/01 11:36  댓글주소  수정/삭제  댓글쓰기

    관리자만 볼 수 있는 댓글입니다.

다음 지도 API 를 활용해서 지도를 만드는 비교적 간단한 샘플입니다. 아래 소개된 소스 코드를 실행하면 100개의 마커가 뿌려지고 해당 마커를 클릭하면 이미지를 보여주는 다음과 같은 실행 화면을 확인할 수 있습니다. 자신의 홈페이지에서 테스트 하기 위해서는 다음 지도 API 키를 해당 홈페이지 (https://apis.daum.net/register/mapsapi.daum) 에서 얻을 수 있으며 키 값($daum_map_api_key)을 얻은 API 키로 교체해야 합니다. 참고로 구글 지도 API에도 관심이 있는 분은 앞서 소개한 "자바스크립트로 지도 만들기, 구글 지도 API 매시업(Mashup)" 포스트도 참고하세요.

[실행 화면] http://www.hompydesign.com/map/daum.html


[소스 코드]
<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<TITLE><?=$hompy_title?></TITLE>
<script type="text/javascript" src="/js/jquery.js"></script>
<script type="text/javascript" src="http://apis.daum.net/maps/maps.js?apikey=<?=$daum_map_api_key;?>" charset="utf-8"></script>
<style type="text/css">

#map_box {position:relative;}
#map_canvas { width: 578px; height: 460px; margin: 0; padding: 0; border: 0; }

#map_box {width:578px; border: 4px solid #cccccc; padding:2px;}
#display_loading_box {width:578px; height:460px; position:absolute; background-color:#000000; z-index:1000; opacity: 0.5; filter: alpha(opacity = 50);}
#display_loading_box_icon {margin: 214px 273px; width:32px; height:32px;}

body,td,tr { font-size:12px; font-family:돋움,verdana,arial,sans serif;}

.window_image {border:1px solid #cccccc; width:140px; height:100px; margin:6px;}

</style>
<script type='text/javascript'>
<!--

var map = null;
var current_lon = 127.046;
var current_lat = 37.5066;
var current_zoom = 14;
var person_list = [];

$(document).ready(function(){
      display_loading();
      map = new DMap("map_canvas");
      map.setCenter(new DLatLng(current_lat, current_lon), 4);
      //map.addControl(new DIndexMapControl());
      map.addControl(new DZoomControl());

      display_marker({user:0,lat:current_lat,lon:current_lon});
      for (record in person_list) {
            display_marker(person_list[record]);
      }
      setTimeout(display_loaded, 1000);
});

function display_loading(){
      var html = "<div id='display_loading_box'><img src='images/loading.gif' id='display_loading_box_icon' /></div>";
      $('#map_canvas').before(html);
}

function display_loaded(){
      $('#display_loading_box').remove();
}

function display_marker(record){
      var icon = new DIcon("http://localimg.daum-img.net/localimages/07/2008/map/i_mks_b1.gif", new DSize(13, 16));
      var point = new DLatLng(Number(record.lat),Number(record.lon));
      var marker = create_marker(point, record.user);
      map.addOverlay(marker, {mark:icon});
      //map.addOverlay(marker);
}

function create_marker(point, person) {
      var html = '<a href="http://hompy.info/582"><img src="/hompydesign.com?seq='+person+'" class="window_image"></a>';
      var marker= new DMark(point, { infowindow : new DInfoWindow(html), draggable : false });
      //marker.addAutoExpand("pos:"+person);
      return marker;
}

person_list =
[{user:1,lon:127.034,lat:37.5059},{user:2,lon:127.029,lat:37.5125},{user:3,lon:127.032,lat:37.5306},{user:4,lon:127.034,lat:37.4994},{user:5,lon:127.036,lat:37.5169}];

-->
</script>
</HEAD>

<BODY>
<div id="map_box">
<div class="map" id="map_canvas"></div>
</div>
</BODY>
</HTML>

웹프로그래머의 홈페이지 정보 블로그 http://hompy.info/582

댓글을 달아 주세요

  1. 질문이요! 2011/03/24 18:54  댓글주소  수정/삭제  댓글쓰기

    지도 키 발급 받을때요~ http://www.test.com/ 이렇게 도메인으로만 받으면 안되는건가요?? 전 자꾸 스크립트 에러가 떠서 ㅠㅠ

    그리고 저 소스 그대로 긁어다가
    키만 바꿔줬는데 백지로 나옵니다 ㅠ

  2. 임채경 2010/06/23 11:15  댓글주소  수정/삭제  댓글쓰기

    항상 유용한 정보를 눈팅으로만 보고가다가 감사인사 올립니다.
    도움이 많이 되고 있습니다. 감사해요^^

네이버 지도 API 를 활용해서 지도를 만드는 비교적 간단한 샘플입니다. 아래 소개된 소스 코드를 실행하면 100개의 마커가 뿌려지고 해당 마커를 클릭하면 이미지를 보여주는 다음과 같은 실행 화면을 확인할 수 있습니다. 자신의 홈페이지에서 테스트 하기 위해서는 네이버 지도 API 키를 해당 홈페이지 (http://dev.naver.com/openapi/register) 에서 얻을 수 있으며 키 값($naver_map_api_key)을 얻은 API 키로 교체해야 합니다. 참고로 구글 지도 API에도 관심이 있는 분은 앞서 소개한 "자바스크립트로 지도 만들기, 구글 지도 API 매시업(Mashup)" 포스트도 참고하세요.

[실행 화면] http://www.hompydesign.com/map/naver.html


[소스 코드]
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title><?=$hompy_title?></title>
<script type="text/javascript" src="/js/jquery.js"></script>
<script type="text/javascript" src="http://map.naver.com/js/naverMap.naver?key=<?=$naver_map_api_key?>"></script>
<style type="text/css">

#map_box {position:relative;}
#map_canvas { width: 578px; height: 460px; margin: 0; padding: 0; border: 0; }

#map_box {width:578px; border: 4px solid #cccccc; padding:2px;}
#display_loading_box {width:578px; height:460px; position:absolute; background-color:#000000; z-index:1000; opacity: 0.5; filter: alpha(opacity = 50);}
#display_loading_box_icon {margin: 214px 273px; width:32px; height:32px;}

body,td,tr { font-size:12px; font-family:돋움,verdana,arial,sans serif;}

.window_image {border:1px solid #cccccc; width:140px; height:100px;}

</style>
<script type="text/javascript">

var map;
var tm128 = new NPoint(315741,544301);
var latlng;
var person_list;
var infowin;

$(document).ready(function(){
      display_loading();
      map = new NMap($('#map_canvas')[0],578,460);
      map.setCenterAndZoom(tm128, 4);
      //map.addControl(new NIndexMap());
      map.addControl(new NZoomControl());
      map.addControl(new NMapBtns());
      map.enableWheelZoom();
      for (record in person_list) {
            display_marker(person_list[record]);
      }
      display_marker({user:0,lon:127.046,lat:37.5066});
      map.setCenter(latlng);

      NEvent.addListener(map,"click",function (latlng){
            if (infowin) map.removeOverlay(infowin);
      });

      NEvent.addListener(map,"startDrag",function (latlng){
            if (infowin) map.removeOverlay(infowin);
      });
      setTimeout(display_loaded, 1000);
});

function transFromTM128ToLatLng() {
      latlng = map.fromTM128ToLatLng(tm128);
      document.getElementById("display").innerHTML = latlng;
}

function moveLatLng() {
      map.setCenter(latlng);
}

function display_marker(record) {
      latlng = new NLatLng(record.lat, record.lon);
      var marker = new NMark(latlng, new NIcon('http://static.naver.com/maps/ic_spot.png',new NSize(52,41),new NSize(14,40)));
      var html = '<a href="http://hompy.info/580"><img src="/hompydesign.com?seq='+record.user+'" class="window_image"></a>';
      map.addOverlay(marker);
      NEvent.addListener(marker,"click",function (latlng){
            if (infowin) map.removeOverlay(infowin);
            infowin = new NInfoWindow();
            map.addOverlay(infowin);
            infowin.set(latlng, "<TABLE style='width:100px;height:50px;background-color:#FFFFFF; border:solid 1px #666666'><TR><TD>"+html+"</TD></TR></TABLE>");
            infowin.showWindow();
            //NEvent.addListener(infowin,"mouseout",function () {infowin.hideWindow();});
      });
}

function display_loading(){
      var html = "<div id='display_loading_box'><img src='images/loading.gif' id='display_loading_box_icon' /></div>";
      $('#map_canvas').before(html);
}

function display_loaded(){
      $('#display_loading_box').remove();
}

person_list =
[{user:1,lon:127.034,lat:37.5059},{user:2,lon:127.029,lat:37.5125},{user:3,lon:127.032,lat:37.5306},{user:4,lon:127.034,lat:37.4994},{user:5,lon:127.036,lat:37.5169}];

</script>
</head>
<body>

<div id="map_box">
<div class="map" id="map_canvas"></div>
</div>

</body>
</html>

웹프로그래머의 홈페이지 정보 블로그 http://hompy.info/581

댓글을 달아 주세요

  1. 비밀방문자 2011/04/06 16:30  댓글주소  수정/삭제  댓글쓰기

    관리자만 볼 수 있는 댓글입니다.

  2. 최소청 2010/05/25 15:41  댓글주소  수정/삭제  댓글쓰기

    안녕하세요 ^^
    소스를 참고하여 지도 API를 이용한 인물검색시
    "대구광역시 북구"를 검색하게되면
    대구광역시 북구에 사시는 분들이
    마커점이 찍히도록 하고 싶습니다.

    그런데 위에 소스는 강제적으로 마크점이 찍히는 부분을
    정해서 넣은 소스잖아요 ^^

    저 부분을 어떻게 수정을해야 디비에 저장되어 있는 분들을
    지도상에 마커점이 찍히도록 할 수 있습니까~?

    쫌 알려주세요 ㅠㅠ 부탁드립니다 ~

  3. fdsfdsafasdfds 2009/11/13 17:50  댓글주소  수정/삭제  댓글쓰기

    person_list = [{user:1,lon:127.034,lat:37.5059},

    소스를 보니 수동으로 5개를 넣는 소스 이더군요..


    db에 있는 자료의 주소값을 수시로 예를 들어 강남구 역삼동 124,124,125 ......

    처럼 주소값을 lon,lat처럼 위치값으로 어떻게 변화를 시키나요...

    네이버의 geocode.php는 일일히 한개의 주소값(서울시 강남구 역삼동)을

    대입시켜 x,y값만을 뽑아 와야 하는데 여기의 lon,lat값은 사용자가

    어떻게 입력(주소를 lon,lat)값으로 변환시킬수 있나요...

    간절히 부탁드립니다. 일주일 내내 삽집하니 너무 지쳐서요...

  4. 박중호 2009/07/14 18:02  댓글주소  수정/삭제  댓글쓰기

    잘 보고 갑니다.
    유용한 자료 감사합니다.
    그런데 저기 이미지는 어디서가져 왔는지요..ㅜㅜ
    직접 링크를 시키셨나요?

구글 지도 API 를 활용해서 지도를 만드는 비교적 간단한 샘플입니다. 아래 소개된 소스 코드를 실행하면 100개의 마커가 뿌려지고 해당 마커를 클릭하면 이미지를 보여주는 다음과 같은 실행 화면을 확인할 수 있습니다. 자신의 홈페이지에서 테스트 하기 위해서는 구글 지도 API 키를 해당 홈페이지 (http://code.google.com/apis/maps/) 에서 얻을 수 있으며 키 값($google_map_api_key)을 얻은 API 키로 대입해야 합니다.

[실행 화면] http://www.hompydesign.com/map/


[소스 코드]
<HTML>
<HEAD>
<TITLE><?=$hompy_title?></TITLE>
<script type="text/javascript" src="/js/jquery.js"></script>
<script type="text/javascript" src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=<?=$google_map_api_key?>"></script>
<style type="text/css">

#map_box {position:relative;}
#map_canvas { width: 578px; height: 460px; margin: 0; padding: 0; border: 0; }

#map_box {width:578px; border: 4px solid #cccccc; padding:2px;}
#display_loading_box {width:578px; height:460px; position:absolute; background-color:#000000; z-index:1000; opacity: 0.5; filter: alpha(opacity = 50);}
#display_loading_box_icon {margin: 214px 273px; width:32px; height:32px;}

body,td,tr { font-size:12px; font-family:돋움,verdana,arial,sans serif;}

</style>
<script type='text/javascript'>
<!--

var map = null;
var current_lon = 127.046;
var current_lat = 37.5066;
var current_zoom = 14;
var person_list = [];

$(document).ready(function(){
      display_loading();
      map = new google.maps.Map2($("#map_canvas")[0]);
      map.disableDoubleClickZoom();
      map.addControl(new GLargeMapControl());
      map.addControl(new GMapTypeControl());
      map.addControl(new GScaleControl());
      map.enableScrollWheelZoom();
      map.setCenter(new GLatLng(current_lat, current_lon), current_zoom);
      display_marker({user:0,lat:current_lat,lon:current_lon});
      for (record in person_list) {
            display_marker(person_list[record]);
      }
      setTimeout(display_loaded, 1000);
});

function display_loading(){
      var html = "<div id='display_loading_box'><img src='images/loading.gif' id='display_loading_box_icon' /></div>";
      $('#map_canvas').before(html);
}

function display_loaded(){
      $('#display_loading_box').remove();
}

function display_marker(record){
      with (record) {
            var point = new GLatLng(Number(lat),Number(lon));
            var marker = create_marker(point, user);
      }
      map.addOverlay(marker);
      //map.setCenter(point, current_zoom, G_NORMAL_MAP);
}

function create_marker(point, person) {
      var icon = new GIcon(G_DEFAULT_ICON);
      if (person) {
            icon.image = "images/marker"+(person%10)+".png";
            icon.iconSize = new GSize(20,34);
      }
      var marker = new GMarker(point,{'icon': icon});
      marker.person = person;
      GEvent.addListener(marker, "click", function() {
            marker.openInfoWindowHtml('<img src="/hompydesign.com?seq='+person+'" width=140 height=100>');
      });
      return marker;
}

person_list =
[{user:1,lon:127.034,lat:37.5059},{user:2,lon:127.029,lat:37.5125},{user:3,lon:127.032,lat:37.5306},{user:4,lon:127.034,lat:37.4994},{user:5,lon:127.036,lat:37.5169}];

-->
</script>
</HEAD>

<BODY>
<div id="map_box">
<div class="map" id="map_canvas"></div>
</div>
</BODY>
</HTML>

웹프로그래머의 홈페이지 정보 블로그 http://hompy.info/580

댓글을 달아 주세요

  1. 김아름 2010/02/16 14:25  댓글주소  수정/삭제  댓글쓰기

    사용해봤는데 일부러 고쳐서쓰라고 제대로 작동안되게 하신건가요?
    실수한건 아닌것 같고 일부러 그러신것 같네요
    다른사람이 노력해서 얻은 결과물을 아무 노력없이 얻으려는 마음은
    조금 없지않아 있지만 적어도 고쳐서 쓰라고 얘기는 해줬으면 좋겠네요
    한번 사용해 봤습니다. 다른곳엔 쓰지 않겠습니다

  2. Mizix 2009/07/23 16:45  댓글주소  수정/삭제  댓글쓰기

    이거 스크랩 해가도 되나요? ^^
    출처는 당연히 남기구요..

  3. 웹프로그래머 2009/07/14 07:14  댓글주소  수정/삭제  댓글쓰기

    jQuery 에 대해서 궁금하신 분들은 jQuery 관련 게시물과 jQuery 문서를 참고하세요.
    http://hompy.info/tag/jQuery
    http://docs.jquery.com/

  4. 나무 2009/07/13 18:28  댓글주소  수정/삭제  댓글쓰기

    저도 궁금한데 jquery.js 파일은 뭐죠??
    아 웹.. 초보인데 어딜가도 명쾌한 해답을 해주는 곳이 없네요 ㅠ

  5. 성의재 2009/07/02 19:19  댓글주소  수정/삭제  댓글쓰기

    <script type="text/javascript" src="/js/jquery.js"></script>
    이 부분의 jquery.js 파일은 제 홈페이지 안에 있어야 하는 파일인가요?

  6. 버파 2009/06/22 21:56  댓글주소  수정/삭제  댓글쓰기

    저 이거 블로그에 쓰고싶은데요 블로그 html로하면 헤드부분을 못쓰는데 어떻게해요?

최근에 구글 지도 API를 매시업(Mashup)해서 세계 지도를 펼쳐 확대 또는 축소 해가며 인맥의 위치와 분포를 한 눈에 확인할 수 있는 인맥 지도 서비스를 공개 했습니다. 아마도 가까운 지역의 인맥이나 목적지 또는 출장지/여행지에 위치한 인맥을 손쉽게 찾아 볼 수 있으므로 지도를 통해 인맥들과 가까워 지는 계기가 될 수 있을 것 같습니다. 인맥들은 지도 위에 마커(marker)로 표시되며 이 마커를 클릭하면 작은 창이 요약된 프로필 정보를 보여주며 프로필 정보 내에 있는 링크를 클릭해서 보다 상세한 프로필을 확인할 수 있게 됩니다. 그리고 구분된 카테고리나 가나다 기준으로 검색하거나 키워드로 인맥을 검색할 수 있게 했습니다. 인맥 지도의 전반적인 기능 자체는 단조로운 반면 그에 비해 활용도는 높을 것 같습니다.

[인맥 지도 서비스 실행 화면] http://www.linknow.kr/map/


짧은 시간 맛을 봤던 구글 지도 매쉬업 개발 작업은 다른 개발 일정으로 인해 아쉽게 마무리 해야 했지만 기회가 되다면 개선해야 할 부분 몇가지를 보완해볼 것이며 또 다른 형태나 조합으로 매쉬업 개발 작업을 해 볼 생각입니다. 개선했으면 하는 부분은 인맥이 수백명, 수천명 이상일 경우 마커의 갯수가 늘어나서 자바스크립트의 성능 한계로 인해 느려지는 현상이 생기는데 이를 보완해야 하는 부분과 중복되는 좌표에 있는 마커들이 탭이나 스크롤과 같은 UI로 표현될 수 없을 만큼 많아질 경우 어떻게 좀더 효과적인 비쥬얼로 보여줄까 하는 것 입니다.

웹프로그래머의 홈페이지 정보 블로그 http://hompy.info/579

댓글을 달아 주세요

  1. Doer 2009/07/14 00:09  댓글주소  수정/삭제  댓글쓰기

    오... 현재 저희 회사에서 고민하고 있는 문제들입니다. 잘 보았습니다. 감사합니다!^^

플래시 CS4 툴을 이용해서 3D 좌표 속성을 주기적으로 변경하여 소녀시대 맴버 사진들을 입체적으로 회전시켜보는 간단한 플래시 시계를 만들어보았습니다. "내 사진으로 만드는 재미있는 플래시 시계"라는 포스트에서 소개한 플래시를 약간 개조한 것입니다. 재미삼아 취미로 사용했던 플래시를 오랜만에 다뤄보려니 새롭게 습득해야할 것들이 많아졌군요. 당분간 플래시에 시간 투자를 해야할까봐요.


addEventListener(Event.ENTER_FRAME, rotate_movieclip);
function rotate_movieclip(event:Event):void {
    mc_box.rotationY+=2;
    //mc_box.rotationX+=3;
    mc_box.rotationZ+=1;
}

<embed src="http://www.hompydesign.com/flash/3dclock.swf" quality="high" width="240" height="240" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></embed>

웹프로그래머의 홈페이지 정보 블로그 http://hompy.info/578

댓글을 달아 주세요

  1. 얼음사랑 2009/11/09 19:31  댓글주소  수정/삭제  댓글쓰기

    그림이 바뀌면서..멋있습니다.

  2. 외톨이 2009/09/17 19:10  댓글주소  수정/삭제  댓글쓰기

    안녕하세요

  3. 윤광영 2009/09/12 17:25  댓글주소  수정/삭제  댓글쓰기

    와-_-;;; 멋지시다

  4. 피노키오 2009/06/20 14:44  댓글주소  수정/삭제  댓글쓰기

    이글은 태그공개 안해주시나바용 ㅠ_ㅠ

  5. 비밀방문자 2009/06/15 11:54  댓글주소  수정/삭제  댓글쓰기

    관리자만 볼 수 있는 댓글입니다.

자바스크립트 프레임워크 jQuery 를 활용해서 텍스트 입력 박스 (TextArea) 에 크기 조절 막대를 추가해 봅시다. 아래 소개한 소스를 실행하면 입력 박스 하단에 막대가 추가 되며 이 막대를 위 아래로 드래그 할 수 있으며 드래그 방향에 따라 텍스트 박스 크기를 늘리거나 줄일 수 있습니다.

[크기 조절 막대 예제 자바스크립트 소스 코드]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>TextArea Resize Demo</title>
<style type="text/css">
#in_content {width:511px; height:40px; border:1px solid #666666}
.resize_bar {background: url("images/resize_bar.gif"); cursor:s-resize; height:12px; width:100%;}
</style>
<script type="text/javascript" src="/js/jquery.js"></script>
<script type='text/javascript'>
<!--
jQuery.fn.resizehandle = function() {
      return this.each(function() {
            var me = jQuery(this);
            me.after(
                  jQuery('<div class="resize_bar"></div>')
                        .bind('mousedown', function(e) {
                              var h = me.height();
                              var y = e.clientY;
                              var movehandler = function(e) {
                                    me.height(Math.max(40, e.clientY + h - y));
                              };
                              var uphandler = function(e) {
                                    jQuery('html').unbind('mousemove',movehandler)
                                          .unbind('mouseup',uphandler);
                              };
                              jQuery('html') .bind('mousemove', movehandler)
                                    .bind('mouseup', uphandler);
                        })
            );
      });
}
$(document).ready(function(){
      $("textarea").resizehandle();
});
</script>
</head>
<body>

<table cellspacing=0 cellpadding=0 border=0><tr><td>
<textarea name="in_content" id="in_content">아래 크기조절 막대를 이동해보세요.</textarea>
</td></tr></table>
</body>
</html>

[크기 조절 막대 예제 실행 결과]

웹프로그래머의 홈페이지 정보 블로그 http://hompy.info/577

댓글을 달아 주세요

  1. 플모 2009/08/06 14:31  댓글주소  수정/삭제  댓글쓰기

    ㅜ 13번라인

시간 차이를 계산하고 이를 출력하는 함수를 만들어 보고 이를 통해 시간 관련 함수 date, strtotime 사용법을 알아보도록 합시다. 아래 PHP 소스 코드는 사용자 정의 함수 datetimediff 를 호출해서 현재 시간 또는 특정 시간을 기준으로 참조 시간과의 시간차를 계산하고 출력합니다.

[시간 차이 계산 실행 결과]

2009-06-06 12:02:28
2009-06-06 09:11:04
2009-06-06 13:15:03
2시간 전
2시간 51분 24초 전
4시간 3분 59초 전

[시간 차이 계산 PHP 소스 코드]
<?

$ctime = date('Y-m-d H:i:s');
//$rtime = "1942-01-01 00:00:01";
//$rtime = "1941-05-19 09:00:00";
//$rtime = "20090606";
//$rtime = "20090606093924";
//$rtime = "2009-06-06 09:39:24";
$rtime = date('Y-m-d H:i:s', strtotime("-2 hours -51 minutes -24 seconds"));
$xtime = date('Y-m-d H:i:s', strtotime("+1 hours 12 minutes 35 seconds"));

echo
"$ctime<br>\n";
echo "$rtime<br>\n";
echo "$xtime<br>\n";

echo datetimediff($rtime) . "<br>\n";
echo datetimediff($rtime, null, "ALL") . "<br>\n";
echo datetimediff($rtime, $xtime, "ALL") . "<br>\n";

function datetimediff($rtime, $ctime = null, $option = null){
      if ($ctime) $cur_time = strtotime($ctime);
      else $cur_time = time();
      $ref_time = strtotime($rtime);

      $cur_date = floor($cur_time / 86400);
      $ref_date = floor($ref_time / 86400);

      $datetimediff = $cur_time - $ref_time;
      $datedist = $cur_date - $ref_date;
      $datediff = floor($datetimediff / 86400);
      $weekdiff = floor($datediff / 7);
      $timediff = $datetimediff % 86400;

      $hour = floor($timediff / 3600);
      $min = floor($timediff % 3600 / 60);
      $sec = floor($timediff % 3600 % 60);

      $result = "";
      if ($datedist>34) {
            $result = date("Y년 n월 j일", $ref_time);
      } else if ($weekdiff>0) {
            $result = $weekdiff . "주 전";
      } else {
            if ($datediff>0) {
                  $result = $datedist . "일 전";
            } else if ($timediff<=0) {
                  $result = "1초 전";
            } else {
                  if ($hour) $result = $hour . "시간";
                  else if ($min) $result = $min . "분";
                  else $result = $sec . "초";
                  if ($result) $result .= " 전";
            }
      }
      if ($option=='ALL') {
            $result = "";
            if ($datediff) $result .= ($result?" ":"") . $datediff."일";
            if ($hour) $result .= ($result?" ":"") . $hour."시간";
            if ($min) $result .= ($result?" ":"") . $min ."분";
            if ($sec) $result .= ($result?" ":"") . $sec . "초";
            $result .= " 전";
      }
      return $result;
}

?>

웹프로그래머의 홈페이지 정보 블로그 http://hompy.info/576

댓글을 달아 주세요

  1. 늘처음 2009/11/22 10:41  댓글주소  수정/삭제  댓글쓰기

    좋은 내용 잘 보고 담아갑니다(네이버에서 퍼갔습니다.)