Skip to content

CHICPRO

  • Life Log
  • Cycling Log
  • Photo Log
    • Portrait
    • Landscape
    • Flower
    • Etc
  • Coding Log
  • Information

[jQuery] 위로 스크롤링되는 갤러리 구현

2012-05-08 by 편리

왼쪽과 같은 최근 갤러리에서 리스트를 위로 스크롤링되도록

만들어야 하는 일이 생겼다. 공개된 소스도 많고 방법은 여러

가지가 있겠지만 jQuery를 알고 나서는 왠만한 코드는 스스로

작성해보자는 생각이 강하게 들어서 오늘도 역시 무한삽질..

어려운 부분이 아니라서 생각만 잘 정리하면 쉬울 것 같았는데

아직은 기본이 부족한지 생각보다는 시간이 많이 걸렸다는..

우선 아래는 CSS 코드 중 일부이다.

#BoardLatest .boardWrap .gallery #mg_list { position: relative; width: 278px; height: 105px; overflow: hidden; }
#BoardLatest .boardWrap .gallery #mg_list ul { margin: 0; padding: 0; list-style: none; }
#BoardLatest .boardWrap .gallery #mg_list li { position: absolute; left: 0; top: 105px; width: 291px; height: 105px; }
#BoardLatest .boardWrap .gallery #mg_list li .iwrap { float: left; width: 84px; margin-right: 13px; }
#BoardLatest .boardWrap .gallery #mg_list li .iwrap .image { width: 82px; height: 56px; border: 1px solid #ccc; overflow: hidden; }
#BoardLatest .boardWrap .gallery #mg_list li .iwrap .image img { width: 82px; height: 56px; }
#BoardLatest .boardWrap .gallery #mg_list li .iwrap .subj { width: 84px; height: 32px; text-align: center; padding-top: 10px; color: #666; font-size: 11px; overflow: hidden; }
#BoardLatest .boardWrap .gallery #mg_list li .iwrap .subj a { color: #666; text-decoration: none; }
#BoardLatest .boardWrap .gallery #mg_list li .iwrap .subj a:hover { text-decoration: underline; }

그리고 아래는 HTML 코드의 일부이다.

<div id=”mg_list”>
    <ul>
        <li>
        <?php // 최근갤러리
        $write_table = $g4[‘write_prefix’] . “gallery”;
        $sql = ” select wr_id, wr_subject from $write_table where wr_is_comment = ‘0’ order by wr_num asc limit 0, 9 “;
        $result = sql_query($sql);

        for($i = 0; $row = sql_fetch_array($result); $i++) {
            if($i > 0 && ($i % 3) == 0) {
                echo “</li>n”;
                echo “<li>n”;
            }

            $subject = get_text($row[wr_subject]);
            $href = “$g4[bbs_path]/board.php?bo_table=gallery&wr_id=$row[wr_id]”;

            // 파일정보
            $sql = ” select bf_file from $g4[board_file_table] where bo_table = ‘gallery’ and wr_id = ‘$row[wr_id]’ order by bf_no asc limit 0, 1 “;
            $file = sql_fetch($sql);
            $filepath = “$g4[path]/data/file/gallery/$file[bf_file]”;
            if(trim($file[bf_file]) && file_exists($filepath)) {
                $img = “<img src=”$filepath” alt=”$subject” />”;
            } else {
                $img = “<img src=”$g4[img_path]/noimage.jpg” alt=”$subject” />”;
            }

            $subject = “<a href=”$href”>” . $subject . “</a>”;
            $img = “<a href=”$href”>” . $img . “</a>”;
        ?>
            <div class=”iwrap”>
                <div class=”image”><?php echo $img; ?></div>
                <div class=”subj”><?php echo $subject; ?></div>
            </div>
        <?php
        }

        if($i == 0) {
            echo “<div class=”nolist”>등록된 게시물이 없습니다.</div>”;
        }
        ?>
        </li>
    </ul>
</div><!– /mg_list –>

그리고 마지막으로 jQuery 코드.

<script type=”text/javascript”>
var idx = 0;
var old_idx = 0;
var speed = 1000;
var interval = 3000;
var cnt = $(‘#mg_list li’).size();

$(function() {
    // 갤러리 스크롤링
    $(‘#mg_list li:eq(0)’).animate(
        { “top”: “0px”}, speed,
        function() {
            if(cnt > 1) {
                gallery_interval = setInterval(“gallery_scrolling()”, interval);
            }
        }
    );

    $(‘#mg_list’).hover(
        function() {
            clearInterval(gallery_interval);
        },
        function() {
            gallery_interval = setInterval(“gallery_scrolling()”, interval);
        }
    );
});

function gallery_scrolling()
{
    if(cnt > 1) {
        idx = (old_idx + 1) % cnt;
        $(‘#mg_list li:eq(‘ + old_idx + ‘)’).animate(
            { “top”: “-105px”}, speed,
            function() {
                $(this).css(“top”, “105px”);
            }
        );
        $(‘#mg_list li:eq(‘ + idx + ‘)’).animate({ “top”: “0px” }, speed);
    &nb
sp;   old_idx = idx;
    }
}
</script>

사실 뭐 대단한 코드는 아니다. 더 쉬운 코드가 있을 수도 있는데.. 그냥 혼자 만들어보고 싶어서.. ^^; 그냥 이렇게도

구현을 할 수 있구나 정도로 참고만 하면 될 것 같다. 언제쯤 스스로 작성한 코드에 자신감을 가질 수 있을까?? ㅎㅎ

덧, 위 코드 중 php 코드 부분은 그누보드 기반이라 거기에 있는 걸 그냥 그대로 사용했다. 최근 게시물 스킨을 사용해

구현해도 되는데.. 언제부턴가 그것보다는 직접 코드를 짜는 게 더 편해지기 시작했다는.. ㅎ

Post navigation

Previous Post:

2012년 5월 5일 가든파이브

Next Post:

2012년 5월 9일 지름 품목

2 Commments

  1. 시우아빠 says:
    2012-06-28 at 01:14

    좋은정보감사합니다 ㅍ

    Reply
    1. 편리 says:
      2012-06-29 at 01:03

      블로그 방문해 주시고 댓글 남겨주셔서 감사합니다. 좋은 하루 되세요..

      Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Recent Posts

  • php 배열 연산에서 + 와 array_merge 의 차이
  • pcntl_fork 를 이용한 다중 프로세스 실행
  • 아이폰 단축어를 이용하여 주중 공휴일엔 알람 울리지 않게 하기
  • 구글 캘린더 전체일정 재동기화
  • OpenLiteSpeed 웹서버에 HTTP 인증 적용
  • OpenLiteSpeed 웹어드민 도메인 연결
  • WireGuard를 이용한 VPN 환경 구축
  • Ubuntu 22.04 서버에 OpenLiteSpeed 웹서버 세팅
  • 맥 vim 세팅
  • 우분투 시스템 터미널쉘 zsh 로 변경

Recent Comments

  • 편리 on 업무관리용 그누보드 게시판 스킨
  • 임종섭 on 업무관리용 그누보드 게시판 스킨
  • 캐논 5D 펌웨어 | Dslr 펌웨어 업그레이드 방법 82 개의 베스트 답변 on 캐논 EOS 30D 펌웨어 Ver 1.0.6 , EOS 5D 펌웨어 Ver 1.1.1
  • Top 5 캐논 5D 펌웨어 Top 89 Best Answers on 캐논 EOS 30D 펌웨어 Ver 1.0.6 , EOS 5D 펌웨어 Ver 1.1.1
  • 편리 on 워드프레스 애니메이션 gif 파일을 mp4로 변환하여 출력하기
  • 임팀장 on 워드프레스 애니메이션 gif 파일을 mp4로 변환하여 출력하기
  • 편리 on Notepad++ NppFTP 플러그인 수동 설치
  • paul-j on Notepad++ NppFTP 플러그인 수동 설치
  • YS on Windows 10 iCloud 사진 저장 폴더 변경
  • 편리 on Docker를 이용한 Centos7 + httpd + php 5.4 개발환경 구축

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
© 2025 CHICPRO | Built using WordPress and SuperbThemes