我正在使用100%宽度相对定位,但需要一个绝对定位的子div或span来保存jquery图像滑块。
布局
------宽度100%-------
| img1 |滑块| img2 |
目前,滑块跨度未像其他对象一样内嵌并重叠
到目前为止我所拥有的:
HTML
<div class="pic_container">
<img src="http://www.image-and-text.com/pictures/whiskey_with_ice.jpg">
<span class="viewer">
<img src="http://images.printsplace.co.uk/Content/Images/Products/46576/43569/Image_of_M101_1.jpg" alt="" class="active" />
<img src="http://i.bosity.com/clothes_cache/261/12002348/3480000011312473207_12002348_1_image.jpg" alt="" />
<img src="http://lokeshdhakar.com/projects/lightbox2/images/examples/image-6.jpg" alt="" />
</span>
<img src="http://www.image-and-text.com/pictures/whiskey_with_ice.jpg">
</div>
</div>
CSS
/*slideshow*/
.viewer {
font-size:0;
display:inline;
}
.viewer IMG {
position:absolute;
z-index:8;
width:50%;
vertical-align:top;
}
.viewer IMG.active {
z-index:10;
}
.viewer IMG.last-active {
z-index:9;
}
/*pics*/
.pic_container{
font-size:0;
display:inline;
}
.pic_container img {
width:25%;
vertical-align:top;
}
答案 0 :(得分:1)
我在查看器中添加了一个包装器,并使用html注释标签删除了外部图像和幻灯片显示器之间的额外间距(这比设置font-size:0更好)。我调整了JS,以便过渡工作。我还清理并减少了所需的CSS数量。
<强> HTML 强>
<div class="picture-container">
<img src="http://www.image-and-text.com/pictures/whiskey_with_ice.jpg" /><!--
--><div class="viewer">
<img src="http://images.printsplace.co.uk/Content/Images/Products/46576/43569/Image_of_M101_1.jpg" class="active" />
<img src="http://i.bosity.com/clothes_cache/261/12002348/3480000011312473207_12002348_1_image.jpg" />
<img src="http://lokeshdhakar.com/projects/lightbox2/images/examples/image-6.jpg" />
</div><!--
--><img src="http://www.image-and-text.com/pictures/whiskey_with_ice.jpg" />
</div>
<强> CSS:强>
* {margin:0;padding:0}
.picture-container > img {display:inline-block;width:25%;}
.viewer {display:inline-block;position:relative;width:50%;vertical-align:top;}
.viewer img {position:absolute;width:100%;}
<强> JS 强>
function slideSwitch() {
var transitionDuration = 1000;
var active = $('.viewer img.active');
var next = $('.viewer img:first').insertAfter(active);
active.removeClass('active').fadeOut(transitionDuration);
next.addClass('active').hide().fadeIn(transitionDuration);
}
$(document).ready(function(){
$('.viewer img.active').insertAfter('.viewer img:last');
setInterval("slideSwitch()", 4000);
});
您可以在此处查看:http://jsfiddle.net/Ry7Su/1/
希望这有帮助。
答案 1 :(得分:0)
以下更改将解决您的问题。
这是基于您的代码。你可以调整它以缩短它。
HTML部分:
<div class="pic_container">
<div class="leftDiv">
<img src="http://www.image-and-text.com/pictures/whiskey_with_ice.jpg">
</div><!--
--><div class="viewerWrapper"><div class="viewer">
<img src="http://images.printsplace.co.uk/Content/Images/Products/46576/43569/Image_of_M101_1.jpg" alt="" class="active" />
<img src="http://i.bosity.com/clothes_cache/261/12002348/3480000011312473207_12002348_1_image.jpg" alt="" />
<img src="http://lokeshdhakar.com/projects/lightbox2/images/examples/image-6.jpg" alt="" />
</div></div><!--
--><div class="rightDiv">
<img src="http://www.image-and-text.com/pictures/whiskey_with_ice.jpg">
</div>
</div>
CSS部分:
.pic_container {
display: block;
width: 100%;
position:relative;
}
.leftDiv {
display:inline-block;
width: 25%;
position:relative;
}
.rightDiv {
display:inline-block;
width: 25%;
position:relative;
}
.viewerWrapper {
display:inline-block;
width: 50%;
position:relative;
vertical-align: top;
}
.viewer {
width:100%;
}
.leftDiv IMG, .rightDiv IMG, .viewer IMG {
max-width: 100%;
}
.viewer IMG {
z-index:8;
position: absolute;
}
.viewer IMG.active {
z-index:10;
}
.viewer IMG.last-active {
z-index:9;
}
请在此处查看:http://jsfiddle.net/FTEan/
答案 2 :(得分:0)
尝试提供pic_container
position: relative;
并尝试授予viewer
display: inline-block;
这可能有效。 pic_container
也可能是display: inline-block;