<div> <a href="###"><img src="https://www.jb51.net/ppt/ppt1.jpg" /></a> <a href="###"><img src="https://www.jb51.net/ppt/ppt2.jpg" /></a> <a href="###"><img src="https://www.jb51.net/ppt/ppt3.jpg" /></a> <a href="###"><img src="https://www.jb51.net/ppt/ppt4.jpg" /></a> <div> <span>4</span> <span>3</span> <span>2</span> <span>1</span> </div> </div>
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:
<script type="text/javascript" src="https://www.jb51.net/js/jquery-1.10.1.min.js"></script> <script type="text/javascript" src="https://www.jb51.net/js/ppt.js"></script>
效果图:
更多关于jQuery相关内容感兴趣的读者可查看本站专题:《jQuery切换特效与技巧总结》、《jQuery扩展技巧总结》、《jQuery常用插件及用法总结》、《jQuery拖拽特效与技巧总结》、《jQuery表格(table)操作技巧汇总》、《jquery中Ajax用法总结》、《jQuery常见经典特效汇总》、《jQuery动画与特效用法总结》及《jquery选择器用法总结》