3D Gallery với CSS3 và jQuery Plugin : jquery.gallery.js

Danh mục: Html & Javascript
 

Với 3D transforms , chúng ta có thể biến những phần tử đơn giản trở nên hấp dẫn hơn bằng cách ấn định chúng vào không gian 3 chiều. Cùng với CSS transitions, thì hiệu ứng 3D càng trở nên thực hơn rất nhiều, điều mà trước kia chúng ta chỉ có thể làm được bằng Flash.
Trong bài viết này, mình sẽ chia sẻ cho các bạn cách làm hiệu ứng 3D Gallery đẹp mắt với sự kết hợp giữa CSS3 và jQuery Plugin :jquery.gallery.js.

3D Gallery, gallery, jQuery, jQuery plugin,3D transforms

HTML

Đầu tiên , chúng ta cần có khung html để chứa các hình làm gallery như sau :

<section class="dg-container" id="dg-container">

<div class="dg-wrapper">

   <a href="#">

       <div class="dg-wrapper"><a href="#"><img alt="image01" src="images/1.jpg" /></a>

      <div>http://MANGUON.COM/</div>

   </a>



   <a href="#">

       <img alt="image02" src="images/2.jpg" />

       <div>http://www.percivalclo.com/</div>

   </a>



   <a href="#">

       <img alt="image03" src="images/3.jpg" />

       <div>http://www.wanda.net/fr</div>

   </a>



   <a href="#">

      <img alt="image04" src="images/4.jpg" />

      <div>http://lifeingreenville.com/</div>

   </a>



   <a href="#">

      <img alt="image05" src="images/5.jpg" />

      <div>http://circlemeetups.com/</div>

   </a>

</div>



<nav>

  <span class="dg-prev">&lt;</span>

 <span class="dg-next">&gt;</span>

</nav>



</section>

CSS

Kế tiếp là chúng ta sẽ định dạng CSS cơ bản cho các phần tử tạo gallery

.dg-container{

    width: 100%;

    height: 450px;

    position: relative;

}

.dg-wrapper{

    width: 481px;

    height: 316px;

    margin: 0 auto;

    position: relative;

    -webkit-transform-style: preserve-3d;

    -moz-transform-style: preserve-3d;

    -o-transform-style: preserve-3d;

    -ms-transform-style: preserve-3d;

    transform-style: preserve-3d;

    -webkit-perspective: 1000px;

    -moz-perspective: 1000px;

    -o-perspective: 1000px;

    -ms-perspective: 1000px;

    perspective: 1000px;

}

.dg-wrapper a{

    width: 482px;

    height: 316px;

    display: block;

    position: absolute;

    left: 0;

    top: 0;

    background: transparent url(../images/browser.png) no-repeat top left;

    box-shadow: 0px 10px 20px rgba(0,0,0,0.3);

}

.dg-wrapper a.dg-transition{

    -webkit-transition: all 0.5s ease-in-out;

    -moz-transition: all 0.5s ease-in-out;

    -o-transition: all 0.5s ease-in-out;

    -ms-transition: all 0.5s ease-in-out;

    transition: all 0.5s ease-in-out;

}

.dg-wrapper a img{

    display: block;

    padding: 41px 0px 0px 1px;

}

.dg-wrapper a div{

    font-style: italic;

    text-align: center;

    line-height: 50px;

    text-shadow: 1px 1px 1px rgba(255,255,255,0.5);

    color: #333;

    font-size: 16px;

    width: 100%;

    bottom: -55px;

    display: none;

    position: absolute;

}

.dg-wrapper a.dg-center div{

    display: block;

}

.dg-container nav{

    width: 58px;

    position: absolute;

    z-index: 1000;

    bottom: 40px;

    left: 50%;

    margin-left: -29px;

}

.dg-container nav span{

    text-indent: -9000px;

    float: left;

    cursor:pointer;

    width: 24px;

    height: 25px;

    opacity: 0.8;

    background: transparent url(../images/arrows.png) no-repeat top left;

}

.dg-container nav span:hover{

    opacity: 1;

}

.dg-container nav span.dg-next{

    background-position: top right;

    margin-left: 10px;

}

jQuery

Để hiệu ứng có thể chạy, chúng ta cần chèn thư viện jQuery, jquery.gallery.js và đoạn khai báo đơn giản như sau:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script><script type="text/javascript" src="js/jquery.gallery.js"></script>

<script type="text/javascript">// <![CDATA[

$(function() {    

   $('#dg-container').gallery();

});

// ]]></script>

Plugin jquery.gallery.js các bạn có thể tải về tại phần download và để tùy chỉnh thêm hiệu ứng, các bạn có những lựa chọn sau cho phần khai báo :

current : 0,
// vị trí bắt đầu
autoplay : false,
// tự động chạy
interval : 2000
// thời gian chuyển giữa các hình

Ví dụ khai báo tự động chạy cho các hình ảnh như sau :

<script type="text/javascript">// <![CDATA[

$(function() {     

$('#dg-container').gallery({           

     autoplay:true

  });  

});

// ]]></script>

Mình hy vọng các bạn sẽ cảm thấy thích với hiệu ứng mà plugin này mang đến.

 



BÀI VIẾT KHÁC
CODE GỢI Ý CHO BẠN
BÌNH LUẬN

BẢN QUYỀN ®
Mọi chia sẻ nội dung thuộc tác quyền của MANGUON.COM phải ghi rõ "Nguồn MANGUON.COM"