다이나믹스크롤로딩이란녀석. 정보
다이나믹스크롤로딩이란녀석.
본문
이번에 하이브리드웹을 제작하면서 . 참많은 삽질과 깨달음이 있었습니다.
다이나믹스크롤로딩? 스크롤이 마지막이되었을때 다음 컨텐츠를 로딩하는방식. 요즘 모바일에서 많이 쓰고있는
모바일에선 페이징이아닌 이제 스크롤로딩이 익숙해진 환경이된거같아요.
구글링해서 돌아다니는 수십가지의 스크롤로딩자료를 디비와연동해서 여러모바일기계에서 테스트해봤습니다.
저는 넥서스4최신버젼으로기준으로 모든작업을 했지만 결과적으로. 갤2나 기타 하위버젼 안드로이드 웹뷰에서
스크롤로딩이 안먹히는 기기가있더라구요. 스크롤의 끝에서 스크립트를 실행시키지못하는 문제점들.
이러한 문제때문에 추석내내 수십개의 예제를 테스트해보고 결국 모든기계에서 네이티브못지않은 녀석을
찾고 수정해서 완성했습니다. ㅜㅜ
또한 요스크롤로딩의 가장큰문제점이 중간정도 목록에서 뷰페이지를보고 다시 리스트로 이동하면 페이지가
처음부터 이동하는 사용자입장에서 겁나게짜증나는 구조입니다.
근복적으로 이것을해결하기위해서는 리스트에서 뷰페이지를 별도 창으로띄우는 방법뿐이 없더라구요.
여기서좀더업그레이드해서 페이징의 장점( 사용자가 해당페이지를기억하고있을때 한번에 이동할수있음/게시물을 좀더 빨리 이동해볼수있음) 과 스클롤로딩의 장점을 결합한 좀더 편리한 방식을 고민중에 있습니다.
예를들어 상단에 페이징버튼을누르면 페이징을 터치슬라이드로 움직이면서 해당 페이지로도 이동할수있는 ?
암튼 더좋은 소스나 ㅋ 방법있으면 공유해요~
추천
0
0
댓글 13개

으으..... 매우 따라해보고 싶은기능이네요;; 기회가 된김에 저도 공부를... ㄷㄷ

<?php
include dirname(__FILE__).'/../lib/library.php';
$category1 =$_GET['category'];
?>
<meta http-equiv="content-type" content="text/html; charset=euc-kr">
<link rel="stylesheet" type="text/css" href="/m2/size/style.css" />
<script type="text/javascript" language="javascript" src="/m2/size/jquery.js"></script>
<script>
$(document).ready(function() {
$('#content').scrollPagination({
nop : 10, // The number of posts per scroll to be loaded
offset : 0, // Initial offset, begins at 0 in this case
error : '마지막페이지입니다.', // When the user reaches the end this is the message that is
// displayed. You can change this if you want.
delay : 100, // When you scroll down the posts will load after a delayed amount of time.
// This is mainly for usability concerns. You can alter this as you see fit
scroll : true // The main bit, if set to false posts will not load as the user scrolls.
// but will still load if the user clicks.
});
});
(function($) {
$.fn.scrollPagination = function(options) {
var settings = {
nop : 10, // The number of posts per scroll to be loaded
offset : 0, // Initial offset, begins at 0 in this case
error : '마지막페이지입니다.', // When the user reaches the end this is the message that is
// displayed. You can change this if you want.
delay : 100, // When you scroll down the posts will load after a delayed amount of time.
// This is mainly for usability concerns. You can alter this as you see fit
scroll : true // The main bit, if set to false posts will not load as the user scrolls.
// but will still load if the user clicks.
}
// Extend the options so they work with the plugin
if(options) {
$.extend(settings, options);
}
// For each so that we keep chainability.
return this.each(function() {
// Some variables
$this = $(this);
$settings = settings;
var offset = $settings.offset;
var busy = false; // Checks if the scroll action is happening
// so we don't run it multiple times
// Custom messages based on settings
if($settings.scroll == false) $initmessage = '';
else $initmessage = '마지막상품입니다.'; //원래 더보기 텍스트가들어간 자리. 하지만 로딩시 보이는문제때문에 로딩이란 테스?로바꿔줌
// Append custom messages and extra UI
$this.append('<div class="content"></div><div class="loading-bar">'+$initmessage+'</div>');
function getData() {
// Post data to ajax.php
$.post('/m2/size/ajax.php?ca=<?=$category1?>', {
action : 'scrollpagination',
number : $settings.nop,
offset : offset,
}, function(data) {
// Change loading bar content (it may have been altered)
$this.find('.loading-bar').html($initmessage);
// If there is no data returned, there are no more posts to be shown. Show error
if(data == "") {
$this.find('.loading-bar').html($settings.error);
}
else {
// Offset increases
offset = offset+$settings.nop;
// Append the data to the content div
$this.find('.content').append(data);
// No longer busy!
busy = false;
}
});
}
getData(); // Run function initially
// If scrolling is enabled
if($settings.scroll == true) {
// .. and the user is scrolling
$(window).scroll(function() {
// Check the user is at the bottom of the element
if($(window).scrollTop() + $(window).height() > $this.height() && !busy) {
// Now we are working, so busy is true
busy = true;
// Tell the user we're loading posts
$this.find('.loading-bar').html('불러오는중...');
// Run the function to fetch the data inside a delay
// This is useful if you have content in a footer you
// want the user to see.
setTimeout(function() {
getData();
}, $settings.delay);
}
});
}
// Also content can be loaded by clicking the loading bar/
$this.find('.loading-bar').click(function() {
if(busy == false) {
busy = true;
getData();
}
});
});
}
})(jQuery);
</script>
<div id="content">
</div>
<script>
</script>
</body>
</html>
include dirname(__FILE__).'/../lib/library.php';
$category1 =$_GET['category'];
?>
<meta http-equiv="content-type" content="text/html; charset=euc-kr">
<link rel="stylesheet" type="text/css" href="/m2/size/style.css" />
<script type="text/javascript" language="javascript" src="/m2/size/jquery.js"></script>
<script>
$(document).ready(function() {
$('#content').scrollPagination({
nop : 10, // The number of posts per scroll to be loaded
offset : 0, // Initial offset, begins at 0 in this case
error : '마지막페이지입니다.', // When the user reaches the end this is the message that is
// displayed. You can change this if you want.
delay : 100, // When you scroll down the posts will load after a delayed amount of time.
// This is mainly for usability concerns. You can alter this as you see fit
scroll : true // The main bit, if set to false posts will not load as the user scrolls.
// but will still load if the user clicks.
});
});
(function($) {
$.fn.scrollPagination = function(options) {
var settings = {
nop : 10, // The number of posts per scroll to be loaded
offset : 0, // Initial offset, begins at 0 in this case
error : '마지막페이지입니다.', // When the user reaches the end this is the message that is
// displayed. You can change this if you want.
delay : 100, // When you scroll down the posts will load after a delayed amount of time.
// This is mainly for usability concerns. You can alter this as you see fit
scroll : true // The main bit, if set to false posts will not load as the user scrolls.
// but will still load if the user clicks.
}
// Extend the options so they work with the plugin
if(options) {
$.extend(settings, options);
}
// For each so that we keep chainability.
return this.each(function() {
// Some variables
$this = $(this);
$settings = settings;
var offset = $settings.offset;
var busy = false; // Checks if the scroll action is happening
// so we don't run it multiple times
// Custom messages based on settings
if($settings.scroll == false) $initmessage = '';
else $initmessage = '마지막상품입니다.'; //원래 더보기 텍스트가들어간 자리. 하지만 로딩시 보이는문제때문에 로딩이란 테스?로바꿔줌
// Append custom messages and extra UI
$this.append('<div class="content"></div><div class="loading-bar">'+$initmessage+'</div>');
function getData() {
// Post data to ajax.php
$.post('/m2/size/ajax.php?ca=<?=$category1?>', {
action : 'scrollpagination',
number : $settings.nop,
offset : offset,
}, function(data) {
// Change loading bar content (it may have been altered)
$this.find('.loading-bar').html($initmessage);
// If there is no data returned, there are no more posts to be shown. Show error
if(data == "") {
$this.find('.loading-bar').html($settings.error);
}
else {
// Offset increases
offset = offset+$settings.nop;
// Append the data to the content div
$this.find('.content').append(data);
// No longer busy!
busy = false;
}
});
}
getData(); // Run function initially
// If scrolling is enabled
if($settings.scroll == true) {
// .. and the user is scrolling
$(window).scroll(function() {
// Check the user is at the bottom of the element
if($(window).scrollTop() + $(window).height() > $this.height() && !busy) {
// Now we are working, so busy is true
busy = true;
// Tell the user we're loading posts
$this.find('.loading-bar').html('불러오는중...');
// Run the function to fetch the data inside a delay
// This is useful if you have content in a footer you
// want the user to see.
setTimeout(function() {
getData();
}, $settings.delay);
}
});
}
// Also content can be loaded by clicking the loading bar/
$this.find('.loading-bar').click(function() {
if(busy == false) {
busy = true;
getData();
}
});
});
}
})(jQuery);
</script>
<div id="content">
</div>
<script>
</script>
</body>
</html>

헉..... ㄷㄷ

아~ 나도 공부하고 싶다....ㅠㅠ

<?php
include dirname(__FILE__).'/../lib/library.php';
$category1 =$_GET['ca'];
?>
<style>
.item{border:1px solid #2bb5dc; height:80px; margin-bottom: 5px; background: #fff;}
.img{float: left; width: 80px; height: 80px;}
.i_info{float: left;}
</style>
<?
$offset = is_numeric($_POST['offset']) ? $_POST['offset'] : die();
$postnumbers = is_numeric($_POST['number']) ? $_POST['number'] : die();
$run = mysql_query("SELECT * from gd_goods_link,gd_goods,gd_goods_option
where gd_goods_link.category like '$category1%'
AND gd_goods_link.goodsno= gd_goods.goodsno
AND gd_goods_option.goodsno=gd_goods.goodsno
ORDER BY gd_goods.goodsno DESC LIMIT ".$postnumbers." OFFSET ".$offset);
for($i=0;$row= mysql_fetch_array($run);$i++) {
?>
<a href="javascript:void(0);" onclick="window.HybridApp.setMessage('menu@i_view@<?= $row["goodsno"]; ?>');">
<div class="item">
<div class="img"> <img src="http://kidsmori.com/shop/data/goods/<?=$row[img_s]?>" width=80/> </div>
<div class="i_info">
<em style="float:left; margin-left:20px; margin-top:20px; "> <?=$row[goodsnm]?></em></br>
<em style="float:left; margin-left:20px;"> <?=$row[price]?>원</em>
</div>
<div style="clear:both; "> </div>
</div>
</a>
<?
}
?>
include dirname(__FILE__).'/../lib/library.php';
$category1 =$_GET['ca'];
?>
<style>
.item{border:1px solid #2bb5dc; height:80px; margin-bottom: 5px; background: #fff;}
.img{float: left; width: 80px; height: 80px;}
.i_info{float: left;}
</style>
<?
$offset = is_numeric($_POST['offset']) ? $_POST['offset'] : die();
$postnumbers = is_numeric($_POST['number']) ? $_POST['number'] : die();
$run = mysql_query("SELECT * from gd_goods_link,gd_goods,gd_goods_option
where gd_goods_link.category like '$category1%'
AND gd_goods_link.goodsno= gd_goods.goodsno
AND gd_goods_option.goodsno=gd_goods.goodsno
ORDER BY gd_goods.goodsno DESC LIMIT ".$postnumbers." OFFSET ".$offset);
for($i=0;$row= mysql_fetch_array($run);$i++) {
?>
<a href="javascript:void(0);" onclick="window.HybridApp.setMessage('menu@i_view@<?= $row["goodsno"]; ?>');">
<div class="item">
<div class="img"> <img src="http://kidsmori.com/shop/data/goods/<?=$row[img_s]?>" width=80/> </div>
<div class="i_info">
<em style="float:left; margin-left:20px; margin-top:20px; "> <?=$row[goodsnm]?></em></br>
<em style="float:left; margin-left:20px;"> <?=$row[price]?>원</em>
</div>
<div style="clear:both; "> </div>
</div>
</a>
<?
}
?>

단언컨데 위의스크롤로딩은 지금까지 본최고의 퍼포먼스를자랑하는 소스일껍니다. ㅋ
단언컨대

제가 맞춤법을 신경안써요 ㅋㅋ 정정할께요 단언컨대 ㅜㅜ

차라리 제이쿼리를 쓰겠어요 ㅠㅠ http://skullacy.com/jQuery/505

제가 쓴게 제이쿼리에요 ㅋㅋㅋ

으허..... 재가 아는 제이쿼리가 아니에요 ㅠㅠㅠㅠㅠㅠ

해당 제이쿼리부분만 그냥 한페이지에 몰아서 쓴거에요 ㅋ
1. 가독성 부분의 문제 (jQuery 와 PHP 의 shortcut 사용) 으로 인해 jQuery 안에 PHP 코드는 별로 좋아 보이지 않습니다.
2. script 와 style 의 선언이 표준적이지 않습니다. (doctype 이 보이지 않으니 어느정도 수긍은 됩니다만..)
3. mysql 쿼리 연결 부분에서 bind param 을 사용하지 않아서 추후 잘못된 데이터를 받을 경우 오작동의 여지도 보여집니다.
4. $category1 같이 $_GET 데이터를 받아와 사용하는 변수는 array_key_exists 같은 코드로 값을 검증하는게 여러모로 유익합니다.
2. script 와 style 의 선언이 표준적이지 않습니다. (doctype 이 보이지 않으니 어느정도 수긍은 됩니다만..)
3. mysql 쿼리 연결 부분에서 bind param 을 사용하지 않아서 추후 잘못된 데이터를 받을 경우 오작동의 여지도 보여집니다.
4. $category1 같이 $_GET 데이터를 받아와 사용하는 변수는 array_key_exists 같은 코드로 값을 검증하는게 여러모로 유익합니다.