Skip to content

CHICPRO

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

간단한 갤러리 스라이딩 소스

2012-04-14 by 편리

위 이미지와 같은 개럴리 스라이더를 구현하기 위해 어제 많은 시간을.. 황금같은 금요일에 밤 11시까지 사무실에서

작업을 했으니 내가 미친 것이 아닌가 싶다. ㅋ 이렇게까지 복잡한 기능을 만들려고 한 것은 아닌데.. 자꾸 요구사항을

듣고 기능을 추가하다 보니 대략 난감. ㅎㅎ 동적으로 DB에서 데이터를 불러와서 슬라이드 기능을 구현하는 것이라

상당히 머리를 많이 썼다. 기존에 구현된 것을 찾아서 쓸 걸 그랬나? 하는 생각도 들지만.. 이미 만들어버렸으니까..

<div id=”ViewContents”>
    <div id=”layer_close” class=”png24″></div>
    <div class=”arrow_left png24″></div>
    <div class=”arrow_right png24″></div>
    <div class=”ImageArea”></div>
    <div id=”Explan”>
        <div class=”subject”></div>
        <div class=”explan”></div>
        <div class=”date”></div>
    </div><!– /Explan –>
</div>

HTML 코드이다. 특별한 것은 없다. 그리고 아래는 CSS 코드이다.

#ViewContents { display: none; position: absolute; width: 775px; height: 491px; z-index: 2000; }
#ViewContents .arrow_left { position: absolute; top: 205px; left: 0; width: 27px; height: 50px; background: url(‘./img/arrow_left.png’) no-repeat left top; }
#ViewContents .arrow_right { position: absolute; top: 205px; right: 0; width: 27px; height: 50px; background: url(‘./img/arrow_right.png’) no-repeat left top; }
#ViewContents .pointer { cursor: pointer; }
#ViewContents #layer_close { position: absolute; top: 0; right: 40px; width: 24px; height: 26px; background: url(‘./img/btn_x.png’) no-repeat left top; cursor: pointer; }
#ViewContents .ImageArea { position: absolute; top: 31px; left: 36px; width: 698px; height: 408px; border: 1px solid #ccc; overflow: hidden; background: #fff; }
#ViewContents .ImageArea div { position: absolute; }
#ViewContents #Explan { position: absolute; bottom: 0; left: 36px; width: 700px; height: 43px; background: #000; color: #ccc; font-size: 11px; }
#ViewContents #Explan .subject { position: absolute; left: 16px; top: 5px; height: 14px; padding-top: 0; padding-left: 9px; white-space: nowrap; background: url(‘./img/icon_rect.gif’) no-repeat 0 7px; }
#ViewContents #Explan .subject a { color: #ccc; text-decoration: none; }
#ViewContents #Explan .subject a:hover { text-decoration: underline; }
#ViewContents #Explan .explan { position: absolute; left: 16px; top: 22px; height: 14px; padding-top: 0; padding-left: 9px; white-space: nowrap; background: url(‘./img/icon_rect.gif’) no-repeat 0 7px; }
#ViewContents #Explan .date { position: absolute; right: 15px; bottom: 5px; }

그리고 아래는 자바스크립트 코드이다. 너무 난잡한 코드가 아닌가 싶기도 하다. ^^;

<script type=”text/javascript”>
var current_wr_id;
$(function() {
    $(‘div.image img’).click(function() {
        var w = $(document).width();
        var h = $(document).height();
        var wr_id = $(this).attr(“id”).replace(“con_”, “”);

        $(‘div#overlap’).width(w).height(h).show();

        ViewContents(wr_id, “”);
    });

   $(‘div.arrow_left’).click(function() {
        if($(this).hasClass(“pointer”)) {
            if(!$(‘#ViewContents div.ImageArea div’).is(“:animated”)) {
                var wr_id = $(this).attr(“id”).replace(“con_”, “”);
                ViewContents(wr_id, “left”);
            }
        }
    });

    $(‘div.arrow_right’).click(function() {
        if($(this).hasClass(“pointer”)) {
            if(!$(‘#ViewContents div.ImageArea div’).is(“:animated”)) {
                var wr_id = $(this).attr(“id”).replace(“con_”, “”);
                ViewContents(wr_id, “right”);
            }
        }
    });
});

function ViewContents(wr_id, direction)
{
    $.post(
        ‘<?php echo $board_skin_path; ?>/list.contents.php’,
        { bo_table: “<?php echo $bo_table; ?>”, wr_id: wr_id },
        function(data) {
            if(data.error) {
                alert(data.error);
            } else {
                if(!$(‘#ViewContents’).is(“:visible”)) {
                    $(‘#ViewContents div.ImageArea’).html(data.image);
                } else {
                    $(‘#ViewContents div.ImageArea’).append(data.image);

                    if(direction == “left”) {
                        $(‘#ViewContents div.arrow_left’).removeClass(“active”);
                        $(‘#ViewContents div.ImageArea div#img_’ + wr_id).css(“left”, “698px”).css(“top”, “0px;”);
                        $(‘#ViewContents div.ImageArea div#img_’ + current_wr_id).animate({
                            left: ‘-698px’ }, 1000, ‘swing’,
                            function() {
            &nb
sp;                   $(this).remove();
                            }
                        );
                        $(‘#ViewContents div.ImageArea div#img_’ + wr_id).animate({ left: ‘0px’ }, 1000, ‘swing’);
                    } else if(direction == “right”) {
                        $(‘#ViewContents div.arrow_right’).removeClass(“active”);
                        $(‘#ViewContents div.ImageArea div#img_’ + wr_id).css(“left”, “-698px”).css(“top”, “0px;”);
                        $(‘#ViewContents div.ImageArea div#img_’ + current_wr_id).animate({
                            left: ‘698px’ }, 1000, ‘swing’,
                            function() {
                                $(this).remove();
                            }
                        );
                        $(‘#ViewContents div.ImageArea div#img_’ + wr_id).animate({ left: ‘0px’ }, 1000, ‘swing’);
                    }
                }
                $(‘#ViewContents div.subject’).html(data.subject);
                $(‘#ViewContents div.explan’).html(data.explan);
                $(‘#ViewContents div.date’).html(data.date);

                if(data.prev) {
                    $(‘#ViewContents div.arrow_left’).attr(“id”, data.prev).addClass(“pointer”);
                } else {
                    $(‘#ViewContents div.arrow_left’).removeAttr(“id”).removeClass(“pointer”);
                }

                if(data.next) {
                    $(‘#ViewContents div.arrow_right’).attr(“id”, data.next).addClass(“pointer”);
                } else {
                    $(‘#ViewContents div.arrow_right’).removeAttr(“id”).removeClass(“pointer”);
                }

                if(!$(‘#ViewContents’).is(“:visible”)) {
                    var pos = $(‘#board_list’).position();
                    var top = pos.top – 20;
                    var left = pos.left – 6;
                    $(‘#ViewContents’).css(“left”, left).css(“top”, top).show();
                }

                current_wr_id = wr_id;
            }
        },
        “json”
    );
}
</script>

그리고 마지막으로 DB에서 필요한 데이트를 가져오는 PHP 코드이다.

<?php
include_once(‘./_common.php’);

$write_table = $g4[‘write_prefix’] . $bo_table;
$sql = ” select wr_id, wr_subject, wr_content, wr_link1, wr_1 from $write_table where wr_id = ‘$wr_id’ “;
$row = sql_fetch($sql);
if(!$row[wr_id]) {
    echo json_encode(array(“error”=>”게시글이 존재하지 않습니다.”));
    exit;
}

// 파일정보
$sql = ” select bf_file from $g4[board_file_table] where bo_table = ‘$bo_table’ and wr_id = ‘$wr_id’ order by bf_no asc limit 1, 1 “;
$file = sql_fetch($sql);
$filepath = $g4[‘path’] . ‘/data/file/’ . $bo_table . ‘/’ . $file[bf_file];

$w = 698;
$h = 408;
$ratio = $h / $w;

$size = @getimagesize($filepath);

if(($size[1] / $size[0]) > $ratio) { // 세로가 긴 사진
    if($size[1] > $h) {
        $height = $h;
    } else {
        $height = $size[1];
    }

    $width = round(($w * $height) / $h);
} else {
    if($size[0] > $w) {
        $width = $w;
    } else {
        $width = $size[0];
    }

    $height = round(($width * $h) / $w);
}

// 패딩
$top_pad = round(($h – $height) / 2);
$left_pad = round(($w – $width) / 2);

$image = “<div id=”img_{$wr_id}” style=’padding-top: {$top_pad}px; padding-left: {$left_pad}px;’><img src=”$filepath” width=”$width” height=”$height” /></div>”;

$link = “<a href=”$row[wr_link1]” target=”_blank”>” . $row[wr_link1] . “</a>”;

// 이전컨텐츠
$sql = ” select wr_id from $write_table    where wr_id < $wr_id order by wr_num asc limit 0, 1 “;
$prev = sql_fetch($sql);
if($prev[wr_id]) {
    $prev_id = “con_$prev[wr_id]”;
} else {
    $prev_id = “”;
}

// 다음컨텐츠
$sql = ” select wr_id from $write_table    where wr_id > $wr_id order by wr_num desc limit 0, 1 “;
$next = sql_fetch($sql);
if($next[wr_id]) {
    $next_id = “con_$next[wr_id]”;
} else {
    $next_id = “”;
}

$subject = get_text($row[wr_subject]) . “&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp” . $link;
$explan = get_text($row[wr_content]);
$date = get_text($row[wr_1]);< br />
// 데이터 json 변환
echo json_encode(array(“image”=>$image, “subject”=>$subject, “explan”=>$explan, “prev”=>$prev_id, “next”=>$next_id, “date”=>$date));
exit;
?>

DB 데이터를 json 타입으로 인코딩한 후 전송하고 있다.

Post navigation

Previous Post:

웹페이지 화면을 반투명하게 만들기

Next Post:

ONU Media 홈페이지 오픈 중?

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