Chia sẻ thủ thuật blogspot - blogger

luat1x1

10/14/2011

Tạo Slide Show cho hình ảnh với các ảnh thumb cuộn ngang bên dướ

(Traidatmui.com) – Hôm nay mình xin chia sẻ cùng các bạn thủ thuật tạo Slideshow cho hình ảnh, thủ thuật này mình có thêm hiệu ứng Sroll với 2 mũi tên điều khiển qua lại các ảnh thumb bên dưới các hình ảnh lớn được trình diễn. Bài viết này mình tham khảo code slideshow của nitinh.com, tuy nhiên với slideshow đó thì không có hiệu ứng scroll cho các ảnh thumb. Đây là cái gây khó khăn và phiền phức khi bạn muốn trình diễn với số ảnh nhiều hơn. Nếu không để chế độ Scroll thì ảnh thumb của bạn sẽ dài lê thê. Vì vậy mình kết hợp với JQuery CarouselLite để cho tiện ích trở nên hoàn thiện hơn.

Hình ảnh minh họa

» Bắt đầu thủ thuật

1. Đăng nhập vào tài khoản Blogger
2. Vào phần thiết kế (Design)
3. Chọn chỉnh sửa HTML (Edit HTML)
4. Chèn tiếp code CSS bên dưới vào trước thẻ ]]></b:skin>
.jCarouselLite {float: left;
position: relative;
left: -5000px;
}
.carousel{margin-left:15px;}
.carousel a.prev{
float: left;
width: 18px;
height: 80px;
margin-right:4px;
background: url(https://lh4.googleusercontent.com/-HIBCv5Jv5Qk/Tkd46mA67MI/AAAAAAAAAjw/opmR5hyGa0I/left_gray.png) left 40px no-repeat;
}
.carousel a.next {
float: left;
margin-left:-3px;
width: 18px;
height: 80px;
background: url(https://lh3.googleusercontent.com/-JElA1yXJXVg/Tkd47wJMlqI/AAAAAAAAAkQ/-odO2r0zho4/right_gray.png) right 40px no-repeat;
}

#bigPic{
width:912px;
height:291px;
padding:1px;
border:1px solid #CCC;
background-color:#FFF;
margin-bottom:10px;
}
#bigPic img{
position:absolute;
display:none;
}
ul#thumbs li{
margin:0px;
padding:0;
list-style:none;
}

ul#thumbs li{
float:left;
margin-right:7px;
margin-bottom:5px;
border:1px solid #CCC;
padding:3px;
cursor:pointer;
}
ul#thumbs img{
float:left;
width:80px;
height:80px;
line-height:80px;
overflow:hidden;
position:relative;
z-index:1;
}

5. Chèn tiếp code bên dưới vào trước thẻ </body>
<script type="text/javascript" src="http://traidatmui-tips.googlecode.com/files/jquery.min.v1.4.1.js"></script>
<script src="http://traidatmui-tips.googlecode.com/files/JQuery.eva1.2.3.js" type="text/javascript"></script>
<script type="text/javascript" src="http://traidatmui-tips.googlecode.com/files/jquery.easing.1.1.js"></script>
<script type="text/javascript" src="http://traidatmui-tips.googlecode.com/files/JQ.jCarouselLite.js"></script>
<script type="text/javascript">
$(function() {
$(".jCarouselLite").jCarouselLite({
btnNext: ".next",
btnPrev: ".prev",
speed: 500,
auto:false, // Nếu bạn muốn ảnh tự động cuộn ngang thì thay false thành true
visible:9, // Số ảnh thumb hiển thị
scroll:5, // Số ảnh thumb một lần scroll
easing: "easeinout"
}); });

var currentImage;
var currentIndex = -1;
var interval;
/* <![CDATA[ */ function showImage(index){
if(index < $('#bigPic img').length){
var indexImage = $('#bigPic img')[index]
if(currentImage){
if(currentImage != indexImage ){
$(currentImage).css('z-index',2);
clearTimeout(myTimer);
$(currentImage).fadeOut(250, function() {
myTimer = setTimeout("showNext()", 3000);
$(this).css({'display':'none','z-index':1})
});
}
}
$(indexImage).css({'display':'block', 'opacity':1});
currentImage = indexImage;
currentIndex = index;
$('#thumbs li').removeClass('active');
$($('#thumbs li')[index]).addClass('active');
}
}

function showNext(){
var len = $('#bigPic img').length;
var next = currentIndex < (len-1) ? currentIndex + 1 : 0;
showImage(next);
}

var myTimer;

$(document).ready(function() {
myTimer = setTimeout("showNext()", 3000);
showNext(); //loads first image
$('#thumbs li').bind('click',function(e){
var count = $(this).attr('rel');
showImage(parseInt(count)-1);
});
});

/* ]]> */
</script>

6. Save template lại và trở về phần tử trang (Page Elements)
7. Thêm 1 HTML/Javascript và thêm vào code bên dưới
<div id="bigPic">
<img src="https://lh4.googleusercontent.com/-dwmwhehAUus/TmiK_o5JrUI/AAAAAAAAA0w/5t63K4Wfv3Q/s912/1.jpg" alt="" />
<img src="https://lh4.googleusercontent.com/-6G-Uy5zwOkA/TmiK_KUXnwI/AAAAAAAAA0w/jrewNz2w18I/s912/2.jpg" alt="" />
<img src="https://lh3.googleusercontent.com/-QIc5AWfFPXw/TmiLAeQ9JiI/AAAAAAAAA0w/-W_i8gN9a3Y/s912/3.jpg" alt="" />
<img src="https://lh3.googleusercontent.com/--f0b6s_10GA/TmiLA0KHkwI/AAAAAAAAA0w/CARgfzLwv1g/s912/4.jpg" alt="" />
<img src="https://lh3.googleusercontent.com/-lsE0o-UnRyk/TmiLB2VzNAI/AAAAAAAAA0w/GgHcVhyS1Yw/s912/5.jpg" alt="" />
<img src="https://lh6.googleusercontent.com/-VxkFF-kfBjo/TmiLC-6WrXI/AAAAAAAAA0w/lkENC-50Ibk/s912/6.jpg" alt="" />
<img src="https://lh5.googleusercontent.com/-iZvMTMEbW7E/TmiLDeiXLVI/AAAAAAAAA0w/cvuB0AMWuJo/s912/7.jpg" alt="" />
<img src="https://lh4.googleusercontent.com/-m8HPWXlAjvQ/TmiLDxdM9RI/AAAAAAAAA0w/-3RpxC5DwrE/s912/8.jpg" alt="" />
<img src="https://lh6.googleusercontent.com/-yVAWgB-YBXA/TmiLE4ZmWXI/AAAAAAAAA0w/vxYpgZBfH84/s912/9.jpg" alt="" />
<img src="https://lh5.googleusercontent.com/-4SrBnHMQEHs/TmiLFVjLjSI/AAAAAAAAA0w/ZB20w8TMSkI/s912/10.jpg" alt="" />
</div>

<div class="carousel">
<a href="#" class="prev"></a>
<div class="jCarouselLite">
<ul id="thumbs">
<li class='active' rel='1'><img src="https://lh4.googleusercontent.com/-YnQYffIicLI/TmiK_cZiFCI/AAAAAAAAA0w/p8m-Q1xEnFs/1_thumb.jpg" alt="" /></li>
<li rel='2'><img src="https://lh3.googleusercontent.com/-t5VT9yFpBWM/TmiLA-VXkEI/AAAAAAAAA0w/2bNFaiZsxAs/3_thumb.jpg" alt="" /></li>
<li rel='3'><img src="https://lh5.googleusercontent.com/-DeiS8s4fL6Q/TmiLBHugMSI/AAAAAAAAA0w/zUBeZAEZtxg/4_thumb.jpg" alt="" /></li>
<li rel='4'><img src="https://lh3.googleusercontent.com/-9VoOlMJ62QQ/TmiLBCIuKyI/AAAAAAAAA0w/n10BL_FWDPI/5_thumb.jpg" alt="" /></li>
<li rel='5'><img src="https://lh3.googleusercontent.com/-Q3B9WuIUkEQ/TmiLCtqU6xI/AAAAAAAAA0w/gpi9YnHLTyU/6_thumb.jpg" alt="" /></li>
<li rel='6'><img src="https://lh3.googleusercontent.com/-6xG5Bwiw9Mg/TmiLDT9NfMI/AAAAAAAAA0w/lsLrZh-XjLs/7_thumb.jpg" alt="" /></li>
<li rel='7'><img src="https://lh6.googleusercontent.com/-k5AWRRawSsw/TmiLEG0Z4kI/AAAAAAAAA0w/wdi084w_vtc/8_thumb.jpg" alt="" /></li>
<li rel='8'><img src="https://lh4.googleusercontent.com/-fX8xfvkVe8k/TmiLFIqXf5I/AAAAAAAAA0w/iHI8fxafWBA/9_thumb.jpg" alt="" /></li>
<li rel='9'><img src="https://lh6.googleusercontent.com/-mhr_1-yOxAs/TmiLFj_HdSI/AAAAAAAAA0w/2YdGR8gG8yw/10_thumb.jpg" alt="" /></li>
<li rel='10'><img src="https://lh6.googleusercontent.com/-vMhGOLkEyiU/TmiK_2dSVVI/AAAAAAAAA0w/_xx716b7dR0/2_thumb.jpg" alt="" /></li>

</ul>
</div>
<a href="#" class="next"></a>
</div><div style="clear:both;"/>

Các ảnh bên dưới phần bigPic bạn thay thành các link ảnh lớn tương ứng với các ảnh thumbnail trong phần thumbs. Như vậy là xong.

8. Cuối cùng save tiện ích lại

Share this post
  • Share to Facebook
  • Share to Twitter
  • Share to Google+
  • Share to Stumble Upon
  • Share to Evernote
  • Share to Blogger
  • Share to Email
  • Share to Yahoo Messenger
  • More...

0 nhận xét

:) :-) :)) =)) :( :-( :(( :d :-d @-) :p :o :>) (o) [-( :-? (p) :-s (m) 8-) :-t :-b b-( :-# =p~ :-$ (b) (f) x-) (k) (h) (c) cheer

 
© 2011 Luat1x1
Designed by BlogThietKe Cooperated with Duy Pham
Released under Creative Commons 3.0 CC BY-NC 3.0
Posts RSSComments RSS
Back to top