½ºÅ©·Ñ ¸®½ºÆ®ÀÇ ¾ÆÀÌÅÛ¿¡ ¸¶ÁøÀÌ Æ÷ÇÔ µÇ¾î ÀÖ°í ¾ÆÀÌÅÛÀÇ Å©±â ¹è¼ö¿Í ¸®½ºÆ®ÀÇ ÇÁ·¹ÀÓ Å©±â°¡ ÀÏÄ¡ ÇÏÁö ¾Ê´Â °æ¿ì°¡ ¸¹¾Æ¼ Scroll Äڵ带 ¼öÁ¤ ÇÏ¿´´Ù. ¾ÆÀÌÅÛ¿¡ ¸¶ÁøÀÌ Æ÷ÇԵǾî ÀÖ´Â °æ¿ì ¾ÆÀÌÅÛÀÇ ³ôÀ̸¦ ±¸ÇÏ´Â ¹æ¹ýÀº ´ÙÀ½°ú °°´Ù. ÀÌ ¹æ¹ýÀº ¸¶ÁøÀÌ Æ÷ÇÔ µÇ¾î ÀÖÁö ¾Ê´Ù. var itemHeight1 = view.children[index].offsetHeight; ÀÌ ¹æ¹ýÀº ¸¶ÁøÀÌ Æ÷ÇÔ µÇ¾î ÀÖÁö¸¸ ½ÇÁ¦ °ªÀº parseInt(style.height) + parseInt(style.marginBottom) °ª°ú ÀÏÄ¡ ÇÑ´Ù. var style = window.getComputedStyle(view.children[index],null); var itemHeight2 = parseInt(style.height) + parseInt(style.marginBottom) + parseInt(style.marginTop); ÀÌ ¹æ¹ýÀ¸·Î ¾ÆÀÌÅÛ1°ú ¾ÆÀÌÅÛ2ÀÇ À§Ä¡ Â÷À̸¦ ±¸ÇÒ¼ö ÀÖ´Ù. var h1 = view.children[0].offsetTop; var h2 = view.children[1].offsetTop; var itemHeight = h2 - h1; ´ÙÀ½ÀÇ µÎ°¡Áö ¹æ¹ý¿¡ ´ëÇؼ ¾Ë¾Æ º»´Ù. 1. scrollIntoView ÇÔ¼ö·Î ½ºÅ©·Ñ ÇÏ´Â ¹æ¹ý 2. scrollTopÀ¸·Î ½ºÅ©·Ñ ÇÏ´Â ¹æ¹ý 1. scrollIntoView ÇÔ¼ö·Î ½ºÅ©·Ñ ÇÏ´Â ¹æ¹ývar scrollList = function(oldIndex, curIndex) {
var view = getElement(listname); if(!view.children.length) return; view.children[oldIndex].classList.remove('selectElement'); view.children[index].classList.add('selectElement'); var h1 = view.children[0].offsetTop; var h2 = view.children[1].offsetTop; var itemHeight = h2 - h1; let isUp = (curIndex < oldIndex); if(isUp === false) { var scrollEnd = view.scrollTop + view.clientHeight; var curPos = (index+1) * itemHeight; if(curPos > scrollEnd) view.children[index].scrollIntoView(false); } else { var scrollStart = view.scrollTop; var curPos = (index) * itemHeight; if(curPos <= scrollStart) view.children[index].scrollIntoView(true); } } 2. scrollTopÀ¸·Î ½ºÅ©·Ñ ÇÏ´Â ¹æ¹ývar scrollList = function(oldIndex, curIndex) {
var view = getElement(listname); if(!view.children.length) return; view.children[oldIndex].classList.remove('selectElement'); view.children[index].classList.add('selectElement'); var h1 = view.children[0].offsetTop; var h2 = view.children[1].offsetTop; var itemHeight = h2 - h1; var gap = (curIndex+1)*itemHeight - view.scrollTop; var move = curIndex - oldIndex; if(move > 0 && gap > view.offsetHeight) { view.scrollTop = (curIndex+1)*itemHeight - view.offsetHeight; } if (move < 0 && gap - itemHeight < 0) { view.scrollTop = itemHeight*index; } } scrollIntoView ÇÔ¼ö·Î ½ºÅ©·Ñ ÇÏ´Â ¹æ¹ý : scrollIntoView.html scrollTopÀ¸·Î ½ºÅ©·Ñ ÇÏ´Â ¹æ¹ý : scrollTop.html ÂüÁ¶) Hide Scrollbar : tutorial17.html |