Javascript & JQuery & CSS > $(document), $(window) - scrollTop(), width(), height() - ÀÚµ¿ ½ºÅ©·Ñ ±â´É µî·ÏÀÏ : 2017-07-14 16:44 Á¶È¸¼ö : 145,568¸¶¿ì½º ½ºÅ©·ÑÀ» ³¡±îÁö ³»¸®¸é ½ºÅ©·ÑÀ» °¨Áö Çϰųª (´õº¸±â ±â´É) ¸¶¿ì½º ½ºÅ©·ÑÀ» ³»¸®´Ù°¡ ¹è³Ê°¡ ¸ØÃá´Ù°Å³ª... "¹®Á¦´Â »ç¿ëÀÚ°¡ ½ºÅ©·ÑÀ» ¾Æ·¡±îÁö ³»·ÈÀ» ¶§" À̺¥Æ®¸¦ ijġÇÏ´Â °Í ¿©±â¿¡¼ ¸¶¿ì½º ºê¶ó¿ìÀú âÀÇ ½ºÅ©·Ñ ³¡À» ¾Ë¾Æ³¾¶§.. Çϳª ±Ã±ÝÇÑÁ¡ÀÌ ÀÖ¾ú´Ù. $(window) vs $(document) ÀÇ Â÷ÀÌ.. (Å×½ºÆ®1) //width°íÁ¤ height 100% html { width: 1000px; height:100%; } console.log($(window).width()); //364 console.log($(document).width()); //1000 console.log($(window).height()); //441 console.log($(document).height()); //441 À©µµ¿ì¿Í µµÅ¥¸ÕÆ®´Â °è¼Ó °°¾ÆÁø´Ù. (Å×½ºÆ®2) //width °íÁ¤, height °íÁ¤ html { width: 1000px; height:1000px; } console.log($(window).width()); //364 console.log($(document).width()); //1000 console.log($(window).height()); //441 console.log($(document).height()); //1000 À©µµ¿ì¿Í µµÅ¥¸ÕÆ®´Â css¿¡ µû¶ó °íÁ¤ÀÌ µÈ´Ù. À§¿Í°°ÀÌ º¸¸é css¿¡¼ height¸¦ pxÀÌ³Ä %ÀÌ³Ä µû¶ó ´Þ¶óÁø´Ù. var scroll = $(window).scrollTop(); //½ºÅ©·ÑÀÇ ÇöÀç À§Ä¡ var docHeight = $(document).height() //µµÅ¥¸ÕÆ® ³ôÀÌ·Î °íÁ¤ var winHeight = $(window).height() //À©µµ¿ìâ ³ôÀÌ °¡º¯ console.log(scroll) //1743 console.log(docHeight) //2455 console.log(winHeight)//2546 document = ¹®¼ ±âÁØ..¹®¼´Â ÄÚµù¿¡µû¶ó¼ ´Þ¶óÁö¹Ç·Î °è¼Ó °íÁ¤ window = ºê¶ó¿ìÀúâ ±âÁØ ÀΰŠ°°À½ - â»çÀÌÁî°¡ °è¼Ó ´Þ¶óÁü. â»çÀÌÁî°¡ ÁÙ¾îµé¼ö·Ï window°ªÀº ´Þ¶óÁü. °á·ÐÀº... ½ºÅ©·ÑÀÇ ¸Ç¸¶Áö¸· top°ªÀ» ¾Ë·Á¸é. ¹®¼³ôÀÌ - ºê¶ó¿ìÀúâ³ôÀÌ = ½ºÅ©·Ñ ½ºÅ©·Ñ â ³¡ $(window).scrollTop() == $(document).height() - $(window).height() Æ®À§ÅÍ µî°ú °°Àº ÀÚµ¿ ´õ º¸±â ±â´ÉÀ» ±¸Çö ÇÒ·Á¸é ¾Æ·¡Ã³·³ ÇÏ¸é µÇ°Ú´Ù.... $(document).ready(function() { $(window).scroll(function() { if ($(window).scrollTop() == $(document).height() - $(window).height()) { lastPostFunc(); } }); }); function lastPostFunc() { $('div#lastPostsLoader').html('¸¶Áö¸· ÀÔ´Ï´Ù.............'); };
|