本文实例讲述了jQuery实现简洁的轮播图效果。分享给大家供大家参考,具体如下:
HTML:
css:
/*幻灯片*/
.ppt{ width:270px; height:330px; border:1px solid #ccc; position:relative;}
.ppt img{ position: absolute; top:10px; left:7px; width:255px; height:310px; overflow:hidden;}
.pptNum{ position: absolute; height: 13px; line-height: 14px; bottom:12px; right: 10px; }
.pptNum span{ font-size: 12px; font-weight: 400; color: #FFF; float: right; display: block; width: 24px; text-align: center; background: #000; border-left: solid 1px #FFF; cursor: pointer; }
.pptNum .normal{ color: #FFF; background: #000; filter: Alpha(opacity=50); opacity: .5; }
.pptNum .cur{ background: #ce0609; color: #FFF; }
js:
; (function ($) {
$.fn.extend({
"ppting": function (t) {
var num = 4; //共多少张要轮播的
var $this = $(this), i = 0, $pics = $('.ppt'), autoChange = function () {
var $currentPic = $pics.find('a:eq(' + (i + 1 === num ? 0 : i + 1) + ')');
$currentPic.css({
display: 'block'
}).siblings('a').css({
display: 'none'
});
$pics.find('.pptNum>span:contains(' + (i + 2 > num ? num - i : i + 2) + ')').attr('class', 'cur').siblings('span').attr('class', 'normal');
i = i + 1 === num ? 0 : i + 1;
}, st = setInterval(autoChange, t || 2000);
$this.hover(function () {
clearInterval(st);
}, function () { st = setInterval(autoChange, t || 2000) });
$pics.find('.pptNum>span').click(function () {
i = parseInt($(this).text(), 10) - 2;
autoChange();
});
}
});
}(jQuery));
$('.ppt').ppting(1000);
调用JQ:
效果图:
希望本文所述对大家jQuery程序设计有所帮助。