4

我正在使用 100% 宽度的相对定位,但需要一个绝对定位的子 div 或 span 来容纳 jquery 图像滑块。

布局

------ 宽度 100%------

| 图片1 | 滑块 | 图片2 |

目前,滑块跨度没有像其他对象一样内联定位并且重叠

到目前为止我所拥有的:

小提琴

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;
 }
4

3 回答 3

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/

希望这可以帮助。

于 2013-03-29T03:09:32.647 回答
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/

 

于 2013-03-29T02:35:17.770 回答
0

尝试给予pic_container position: relative;并尝试给予viewer display: inline-block;这可能会奏效。pic_container也可能是display: inline-block;

于 2013-03-29T04:18:20.053 回答