我使用了我的一个小插件:
我稍微修改了你的CSS,通过jQuery将每个图像包装在<span>
元素中。
这样做,我可以使用行高和一些技巧在我的CSS中找到的方法来垂直和水平居中你的图像:
.contentImages{
border:1px solid #CCC;
padding:10px;
margin:20px auto 0;
position:relative;
width: 675px;
height:200px;
overflow:hidden;
background:#fff;
}
.pics{
position:relative;
display:block;
float:left;
width:225px;
height:180px;
}
.pics img {
position:relative;
vertical-align:middle;
background-color: #eee;
max-width:100%;
}
.pics span{
cursor:pointer;
position:absolute;
margin-left:0px;
height:200px;
width:225px;
text-align:center;
background:#444;
line-height:196px;
}
HTML:现在您的所有父元素都具有共同的类pics
,以简化CSS。
<div class="pics pics1">
这是我的jQuery插件(fadeMe!):
(function($){$.fn.fademe = function(F,P,S){F=F||700;S=S-1||0;P=P||3000;var E=this.children(),T;function a(){E.siblings(E).stop().fadeTo(F,0).eq(S=++S%E.length).stop().fadeTo(F,1);}E.on('mouseenter mouseleave click',function(e){var m=e.type==='mouseenter'?clearTimeout(T):(e.type==='click'?a():aa());}).hide().eq(S).show();function aa(){T=setTimeout(function(){a();aa();},F+P);}aa();};})(jQuery);
$('.pics img').each(function(){
$(this).wrap('<span />');
});
$('.pics1').fademe(1360,3500,2);
$('.pics2').fademe(1300);
$('.pics3').fademe(1240,3920);
就是这样。而且这个插件可以让你:
- 在悬停时停止滑动
- 点击以前进
- 自定义淡入时间、暂停和开始幻灯片N
默认设置为:
1.淡入时间=700,暂停=3000,开始幻灯片=1;
您可以在我的页面这里找到更多信息。
style: text-align: center;
,它为我居中对齐了。请确保清除浏览器缓存/历史记录或按Ctrl + F5刷新。 - JonH