繁体   English   中英

垂直居中的jQuery WMU滑块

[英]vertically centering jquery wmu slider

我已经设置了一个滑块,很难将图像全屏显示而不会溢出,并且使其垂直居中并保持导航点在屏幕的最底部。

我对此能获得的任何帮助将不胜感激。

这是网站网址:

http://www.klossal.com/js/wmuSlider/demo/demo3.html

这是代码,

HTML:

<div style="top:50%;">

<div class="wmuSlider example1">
<div class="wmuSliderWrapper" style="height:100%;">
<article>
<img width="612" height="612" src="http://www.klossal.com/portfolio/space_1_header.png"  
/>
</article>
<article>
<img width="612" height="612" src="http://www.klossal.com/portfolio/space_2_header.png" 
/>
</article>
<article>
<img width="612" height="612"     
src="http://farm6.static.flickr.com/5201/5296457034_5688b25c15_z.jpg" />
</article>
<article>
<img width="612" height="612"    
src="http://farm6.static.flickr.com/5245/5291874922_35ca47cc3d_z.jpg" />
</article>
</div>
</div>


</div>
<script>
    $('.example1').wmuSlider({
        touch: Modernizr.touch,
        animation: 'slide',
        slideshow: false
    });
</script>

和CSS:

/* Demo */
.wmuSlider,
.wmuGallery {
margin-bottom: 20px;
}

/* mwuSlider */
.wmuSlider {
position: relative;
overflow: hidden;
}
.wmuSlider .wmuSliderWrapper {
display: none;
}
.wmuSlider .wmuSliderWrapper article {
position: relative;
text-align: center;
}
.wmuSlider .wmuSliderWrapper article img {
max-width: 100%;
height: auto;
}

/* mwuGallery */
.wmuGallery .wmuGalleryImage {
position: relative;
text-align: center;
}
.wmuGallery .wmuGalleryImage img {
max-width: 100%;
height: 100%;
}

/* Default Skin */
.wmuGallery .wmuGalleryImage {
margin-bottom: 10px;
}
 .wmuSliderPrev, .wmuSliderNext {
position: absolute;
width: 40px;
height: 80px;
text-indent: -9999px;
background: url(http://klossal.com/js/wmuSlider/demo/images/sprites.png) no-repeat 0 0;
top: 50%;
margin-top: -40px;
z-index: 2;
}
.wmuSliderPrev {
background-position: 100% 0;
left: 20px;
}
.wmuSliderNext {
right: 20px;
}
.wmuSliderPagination {
z-index: 2;
position: absolute;
left: 50%;
bottom: 0px;
}
.wmuSliderPagination li {
float: left;
margin: 0 5px 0 0;
list-style-type: none;
}
.wmuSliderPagination a {
display: block;
text-indent: -9999px;
width: 10px;
height: 10px;
background: url(http://klossal.com/js/wmuSlider/demo/images/sprites.png) no-repeat 0   
-80px;
}
.wmuSliderPagination a.wmuActive {
background-position: -10px -80px;
}

body{
background:#141414;
}

这是败笔

您有一个容器- <div class="wmuSlider"> -该容器的高度为612px

然后,为滑块图像提供了一个包装器- <div class="wmuSliderWrapper"> -此元素的高度设置为100%。 这意味着它将使用页面包装程序的高度- <div class="wmuSlider"> -的高度为612px。

因此,我们还没有任何间距,我们必须绑定到包装的确切尺寸。 我们继续。

您有<article> ,并且每个<article>都有一个<img> -这些图像的高度(您猜对了)为612px

因此,图像将与周围的所有容器具有相同的高度。

最后,我们有了<ul class="wmuSliderPagination"> 该元素位于元素<div class="wmuSliderWrapper">的底部。 但是,由于图像的高度与包装器的高度相同,因此根据您的z-index:2<ul class="wmuSliderPagination">将具有位于其下方整个612px任何图像。

如果要更改此设置,以使分页没有任何问题,我们可以做一些事情。

我们可以将<div class="wmuSliderWrapper">的高度从100%更改为98%并添加overflow:hidden; ,例如->

.wmuSliderWrapper{
  height:98%;
  overflow:hidden;
}

但是,这会切断图像的底部,我们可能不想这样做。 取而代之的是,我们可以改变的总高度<div class="wmuSlider">和的高度设定<div class="wmuSliderWapper">到一个固定的高度。

.wmuSlider{
  height:632px; //20px is the average line-height of a single element
}
.wmuSliderWrapper{
  height:612px;//give 20pxs of room for the pagination wrapper
}

您的<img>具有硬编码的宽度和高度,因此使用上述解决方案,您永远都不会再遇到这个问题; 但是,如果图像的高度在某些时候有所不同,则需要包括

.wmuSliderWrapper{
  height:612px;
  overflow:hidden; // stop any element that has dimensions larger than the container from overflowing
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM