$(document).ready(function(){

/* data-role="content" 높이 100%로 채우기 */

scroll(0, 0);

var header = $("div[data-role='header']:visible");

var footer = $("div[data-role='footer']:visible");

var content = $("div[data-role='content']:visible");

var viewport_height = $(window).height();

var content_height = viewport_height - header.outerHeight() - footer.outerHeight();

content_height -= (content.outerHeight() - content.height());

$("div[data-role='content']").css('min-height',content_height);

});

1. data-role="header" 또는 data-role="footer"에 사용

2. data-position="fixed" : 페이지가 스크롤 되어도 항상 위치 고정

3. data-tap-toggle="false" : 고정된 위치에서 숨김 기능 제거


AJAX로 Form데이터 전송 (Post/Get)

JAVASCRIPT 2012. 8. 17. 11:48 Posted by Dayis

<SCRIPT LANGUAGE="JavaScript">

<!--

var request;    // URL 요청에 대한 응답을 받아올 객체

var queryString;  // 폼의 모든 입력컨트롤의 값을 QueryString 형태로 저장


/*  

  요청 객체 생성을 위한 랩퍼 함수 

  

  매개변수:

    regType: HTTP 요청 유형. GET 또는 POST

    url: 서버 프로그램의 URL

    asynch: 동기 또는 비동기 모드 선택

*/

function httpRequest(reqType, url, asynch)

{

  if(window.XMLHttpRequest)    // 모질라 기반 브라우저(네스케이프, 파이어폭스)

  {

    request = new XMLHttpRequest();

  }

  else if(window.ActiveXObject)  // IE 기반 브라우저

  {  

    request = new ActiveXObject("MSXML2.XMLHTTP");  // IE 6 이만

    

    if(!request)

    {

      request = new ActiveXObject("Microsoft.XMLHTTP");  // IE 6 이상      

    }

  }


  if(request)

  {

    initReq(reqType, url, asynch);

  }

  else

  {

    alert("이 브라우저는 Ajax 를 지원하지 않습니다.");

  }

}


/*

  생성된 요청 객체의 초기화

  

  매개변수:

    regType: HTTP 요청 유형. GET 또는 POST

    url: 서버 프로그램의 URL

    asynch: 동기 또는 비동기 모드 선택. true 또는 false

*/

function initReq(reqType, url, asynch)

{

  request.onreadystatechange = handleRespone;  // CallBack 함수 지정  


  if(reqType.toLowerCase() == "post")

  {

    // 전송이 post 방식인 경우

    request.open(reqType, url, asynch);

    request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charaset=UTF-8");

    request.send(queryString);

  }

  else

  {

    // 전송이 get 방식인 경우

    request.open(reqType, url + queryString, asynch);

    request.send(null);

  }

}


/*

  Ajax 실행 후 CallBack 함수

*/

function handleRespone()

{

  if(request.readyState == 4)

  {

  // 문서 다운로드가 완료되었는가?

    if(request.status == 200)

    {

    // 문서가 정상적으로 로드되었는가?

      result = request.responseText;

      alert(result); ///* 의미 있는 코드를 넣어두면 되겠지

    }

    else

    {

      alert("해당 URL 에 정상적으로 접근하지 못 했습니다.");

    }

  }

}


/*

  시작 포인트 함수

*/

function sendData()

{

  var url = "http://expert0226.tistory.com/52";


  setQueryString();

  httpRequest("POST", url, true);    ///* GET 으로 전송하고 싶다면 주석 설정

  //httpRequest("GET", url, true);  ///* GET 으로 전송하고 싶다면 주석 해제

}


/*

  폼의 모든 입력컨트롤의 값을 QueryString 형태로 저장

*/

function setQueryString()

{

  queryString = "";

  var frm = document.forms[0];

  var numberElements = frm.elements.length;


  for(var i = 0; i < numberElements; i++)

  {

    input = frm.elements[i];


    if(i < numberElements - 1)

    {

      queryString += input.name + "=" + encodeURIComponent(input.value) + "&";

    }

    else

    {

      queryString += input.name + "=" + encodeURIComponent(input.value);

    }

  }

}

//-->

</SCRIPT>


<TABLE width="100%" height="100%">

<FORM METHOD="POST" ACTION="javascript:void%200;" onSubmit="sendData(); return false;">

<TR height="23px">

  <TD width="140px">이름</TD>

  <TD><INPUT TYPE="text" NAME="txtName" value="여름나라" style="width: 100%;" onFocus="this.select();"></TD>

</TR>

<TR>

  <TD>이야기</TD>

  <TD><INPUT TYPE="text" NAME="txtStory" value="겨울이야기" style="width: 100%;" onFocus="this.select();"></TD>

</TR>

<TR>

  <TD colspan="2" align="center"><INPUT TYPE="submit"></TD>

</TR>

</FORM>

</TABLE>


<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <style>
    #mask {
      position:absolute;
      z-index:9000;
      background-color:#000;
      display:none;
      left:0;
      top:0;
    }
    .window{
      display: none;
      position:absolute;
      left:100px;
      top:100px;
      z-index:10000;
    }
    </style>
    <script src="http://code.jquery.com/jquery-latest.js"></script>
    <script>
    function wrapWindowByMask(){
        //화면의 높이와 너비를 구한다.
        var maskHeight = $(document).height();
        var maskWidth = $(window).width(); 
 
        //마스크의 높이와 너비를 화면 것으로 만들어 전체 화면을 채운다.
        $('#mask').css({'width':maskWidth,'height':maskHeight}); 
 
        //애니메이션 효과 - 일단 1초동안 까맣게 됐다가 80% 불투명도로 간다.
        $('#mask').fadeIn(1000);
        $('#mask').fadeTo("slow",0.8);   
 
        //윈도우 같은 거 띄운다.
        $('.window').show();
    }
 
    $(document).ready(function(){
        //검은 막 띄우기
        $('.openMask').click(function(e){
            e.preventDefault();
            wrapWindowByMask();
        });
 
        //닫기 버튼을 눌렀을 때
        $('.window .close').click(function (e) {
            //링크 기본동작은 작동하지 않도록 한다.
            e.preventDefault();
            $('#mask, .window').hide();
        });      
 
        //검은 막을 눌렀을 때
        $('#mask').click(function () {
            $(this).hide();
            $('.window').hide();
        });
    });
    </script>
</head>
<body>
    <div id="mask"></div>
    <div class="window">
        <input type="button" href="#" class="close" value="나는야 닫기 버튼(.window .close)"/>
    </div>
    <a href="#" class="openMask">검은 막 띄우기</a>
</body>
</html>
 <div id="chapter_select"></div> 레이어창을 브라우져 화면가운데 띄우는 자바스크립트 예제입니다. jQuery로 작성하였습니다. 

function fnOpenChapter() {
var obj = $('#chapter_select');
var iHeight = (document.body.clientHeight / 2) - obj.height() / 2 + document.body.scrollTop;
var iWidth = (document.body.clientWidth / 2) - obj.width() / 2 + document.body.scrollLeft;

obj.css({
position: 'absolute'
, display:'block'
, top: iHeight
, left: iWidth
});
}


여기서 주의할 것은 document.body.scrollTop 와 document.body.scrollLeft 입니다. 화면에 스크롤이 생겨서 스크롤 위치가 변경될 경우에는 스크롤 값도 레이어 위치에 영향을 주므로 해당 값도 확인해서 레이어 위치값에 반영합니다.

$(document).ready(function() {
       var WidthMax ; //브라우저 넓이에 따라 이미지 크기를 달리한다.
WidthMax = ($(window).width()*0.63); //이미지 넓이를 브라우저의 63% 크기로 지정

$(".entry").each(function() {
var imgwidth = $(this).attr("width");
if (imgwidth > WidthMax) 
{
var imgheight = $(this).attr("height");
var ratio = imgwidth/imgheight;
var newHeight = Math.round(WidthMax/ratio);
$(this).attr({width:WidthMax, height:newHeight});
}
});
});

이미지의 width값이 반드시 있어야 한다.
<img src="<%=ImageURL%>" class="entry" width="<%=ImageSize%>"/> 

자바스크립트 타이머

JAVASCRIPT 2011. 7. 13. 10:57 Posted by Dayis
 <script type="text/javascript">
  setTimeout("noti_alert()", 300);//0.3초 후 noti_alert함수를 호출
  setInterval(re,3000); //3초 간격으로 re함수실행
 </script>

jQuery 페이지내 Anchor로 이동

JAVASCRIPT 2011. 5. 4. 11:24 Posted by Dayis
<html>
<head>
<title>TEST</title>
<script src="/jquery/jquery-1.4.4.js" type="text/javascript"></script>
<script type="text/javascript">
<!--
$(document).ready(function(){
$(".scroll").click(function(event){
//prevent the default action for the click event
event.preventDefault();
//get the full url - like mysitecom/index.htm#home
var full_url = this.href;
//split the url by # and get the anchor target name - home in mysitecom/index.htm#home
var parts = full_url.split("#");
var trgt = parts[1];
//get the top offset of the target anchor
var target_offset = $("#"+trgt).offset();
var target_top = target_offset.top;
//goto that anchor by setting the body scroll top to anchor top
$('html, body').animate({scrollTop:target_top}, 500);
});
});
//-->
</script>
</head>
<body>
<div align="center">
<table border="1" cellspacing="1" width="500" id="table1">
<tr>
<td>
<div align="left" id="top">
<table border="0" cellpadding="0" cellspacing="0" width="100" id="table2">
<tr>
<td><a href="#home" class="scroll">HOME</a></td>
</tr>
<tr>
<td><a href="#about" class="scroll">ABOUT</a></td>
</tr>
<tr>
<td><a href="#contact" class="scroll">CONTACT</a></td>
</tr>
</table>
</div>
</td>
</tr>
<tr>
<td height="500" valign="top"><span id="home">HOME AREA</span>
<a href="#top" class="scroll">Go Top</a></td>
</tr>
<tr>
<td valign="top" height="700"><span id="about">ABOUT AREA</span>
<a href="#top" class="scroll">Go Top</a></td>
</tr>
<tr>
<td valign="top" height="800"><span id="contact">CONTACT AREA </span>
<a href="#top" class="scroll">Go Top</a></td>
</tr>
</table>
</div>
</body>
</html>

jQuery 스크롤 페이징

JAVASCRIPT 2011. 3. 14. 18:18 Posted by Dayis
mixsh나 twtkr등에서 스크를 마지막에 가면 자동으로 다음 글들을 불러 오게 하는 자료입니다.
JQUERY로 짜여졌고 간단합니다.

엄청나게 간단하네요....;;;

링크에 실제 배포하는 사이트 남겨 두었습니다.

샘플보기(스크롤해서 내려 보세요) :
http://www.webresourcesdepot.com/dnspinger/


구조설명:

컨텐츠 페이지 구조
<div class="wrdLatest" id=1>content</div>
<div class="wrdLatest" id=2>content</div>
<div id="lastPostsLoader"></div>

로딩중 이미지 보여주는 부분과 실제 데이터 가져오는 부분
function lastPostFunc()
{
    $('div#lastPostsLoader').html('<img src="bigLoader.gif">');
    $.post("scroll.asp?action=getLastPosts&lastID=" + $(".wrdLatest:last").attr("id"),   


    function(data){
        if (data != "") {
        $(".wrdLatest:last").after(data);           
        }
        $('div#lastPostsLoader').empty();
    });
};

스크롤 감지하는 부분
$(window).scroll(function(){
        if  ($(window).scrollTop() == $(document).height() - $(window).height()){
          lastPostFunc();
        }
});

'JAVASCRIPT' 카테고리의 다른 글

자바스크립트 타이머  (0) 2011.07.13
jQuery 페이지내 Anchor로 이동  (0) 2011.05.04
jQuery로 ajax실행 중 로딩이미지  (0) 2010.12.22
jQuery.ajax()를 이용한 페이지 실행  (0) 2010.12.21
JQuery select box  (0) 2010.12.20

jQuery로 ajax실행 중 로딩이미지

JAVASCRIPT 2010. 12. 22. 19:15 Posted by Dayis
jQuery로 ajax실행 중 로딩이미지
→ 첨부파일 참조

'JAVASCRIPT' 카테고리의 다른 글

jQuery 페이지내 Anchor로 이동  (0) 2011.05.04
jQuery 스크롤 페이징  (0) 2011.03.14
jQuery.ajax()를 이용한 페이지 실행  (0) 2010.12.21
JQuery select box  (0) 2010.12.20
jquery 오류  (0) 2010.12.09