简体   繁体   English

垂直居中的jQuery WMU滑块

[英]vertically centering jquery wmu slider

I have a slider that I've set up, I'm having a hard time getting the images to go fullscreen with out overflowing, as well as keeping it vertically centered and keeping the navigation dots at the very bottom of the screen. 我已经设置了一个滑块,很难将图像全屏显示而不会溢出,并且使其垂直居中并保持导航点在屏幕的最底部。

any help I can get on this would be greatly appreciated. 我对此能获得的任何帮助将不胜感激。

This is the site url: 这是网站网址:

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

and this is the code, 这是代码,

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>

and CSS: 和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;
}

Here's the run down 这是败笔

You have a container -- <div class="wmuSlider"> -- this container has a height of 612px 您有一个容器- <div class="wmuSlider"> -该容器的高度为612px

Then you have a wrapper for your slider images -- <div class="wmuSliderWrapper"> -- this element has a height set to 100%. 然后,为滑块图像提供了一个包装器- <div class="wmuSliderWrapper"> -此元素的高度设置为100%。 That means it will use the height of the page wrapper -- <div class="wmuSlider"> -- which is 612px. 这意味着它将使用页面包装程序的高度- <div class="wmuSlider"> -的高度为612px。

So we have no spacing at all yet, we're bound to the exact dimensions of our wrapper. 因此,我们还没有任何间距,我们必须绑定到包装的确切尺寸。 Let's go on. 我们继续。

You have <article> 's, and each <article> has an <img> -- these images have a height of - you guessed it - 612px . 您有<article> ,并且每个<article>都有一个<img> -这些图像的高度(您猜对了)为612px

So the images are going to be the same height as all containers around it. 因此,图像将与周围的所有容器具有相同的高度。

Finally we have <ul class="wmuSliderPagination"> . 最后,我们有了<ul class="wmuSliderPagination"> This element is positioned at the bottom of the element <div class="wmuSliderWrapper"> . 该元素位于元素<div class="wmuSliderWrapper">的底部。 However, because the image has the same height as the wrapper, the <ul class="wmuSliderPagination"> will have any image that spans the full 612px sit beneath it, as per your z-index:2 . 但是,由于图像的高度与包装器的高度相同,因此根据您的z-index:2<ul class="wmuSliderPagination">将具有位于其下方整个612px任何图像。

If we want to change this, so that the pagination doesn't have any issues, we can do a few things. 如果要更改此设置,以使分页没有任何问题,我们可以做一些事情。

We can change the height of the <div class="wmuSliderWrapper"> from 100% to 98% and add overflow:hidden; 我们可以将<div class="wmuSliderWrapper">的高度从100%更改为98%并添加overflow:hidden; , such as-> ,例如->

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

However, this will cut off the bottom of the image, we may not want to do that. 但是,这会切断图像的底部,我们可能不想这样做。 Instead, we can change the overall height of the <div class="wmuSlider"> , and set the height of the <div class="wmuSliderWapper"> to a fixed height. 取而代之的是,我们可以改变的总高度<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
}

Your <img> 's have hard coded width's and height, so with the above solution, you should never run into that problem again; 您的<img>具有硬编码的宽度和高度,因此使用上述解决方案,您永远都不会再遇到这个问题; HOWEVER, if the images vary in height at some point, you would need to include 但是,如果图像的高度在某些时候有所不同,则需要包括

.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