响应式Bootstrap 3图像交换翻转

时间:2013-10-16 22:18:41

标签: jquery html css animation twitter-bootstrap-3

我正在尝试使用Jquery和Bootstrap3进行响应式翻转,但这里是图像必须响应的捕获,它必须是IE7 +兼容,所以这就是为什么我不使用或CSS3背景

我陷入困境,因为到目前为止我尝试过的是在某些方面失败(背景图像没有响应,IE与画布不兼容,位置绝对需要固定的宽度/高度等)可以帮助我吗?这是迄今为止我能够做到的......

HTML:

<div class="row">
    <div class="col-sm-8">
            <ul>
                <li>
                    <div class="img-swap2">
                        <img class="animado img-responsive" src="http://dummyimage.com/125x66/000/fff" alt="" />
                        <img class="animado img-responsive" src="http://dummyimage.com/125x66/fff/000" alt="" />
                    </div>
                </li>
                <li>
                    <div class="img-swap2">
                        <img class="animado img-responsive" src="http://dummyimage.com/125x66/000/fff" alt="" />
                        <img class="animado img-responsive" src="http://dummyimage.com/125x66/fff/000" alt="" />
                    </div>
                </li>
            </ul>
    </div>
</div>
<div class="row">
    <div class="col-sm-4">
        <div class="img-swap2">
            <img class="animado img-responsive" src="http://dummyimage.com/125x66/000/fff" alt="" />
            <img class="animado img-responsive" src="http://dummyimage.com/125x66/fff/000" alt="" />
        </div>
        <div class="img-swap2">
            <img class="animado img-responsive" src="http://dummyimage.com/125x66/000/fff" alt="" />
            <img class="animado img-responsive" src="http://dummyimage.com/125x66/fff/000" alt="" />
        </div>
    </div>
</div>

JQuery的:

$(document).ready(function(){

    $('.img-swap2').hover(
    function(){
        $(this).children("img:eq(0)").fadeTo('400','0');
        $(this).children("img:eq(1)").fadeTo('800','1');
    },
    function(){
        $(this).children("img:eq(0)").fadeTo('800','1');
        $(this).children("img:eq(1)").fadeTo('400','0');
    });
});

CSS

ul {
    list-style-type: none;
    margin-bottom: 0;
}
ul li {
    display: block;
    float: left;
    border-left: 1px solid #333;
    width: 14%;
    max-height: 63px;
}
.img-swap2 {
    position: relative;
    left: 0;
    top: 0;
}
.img-swap2 img + img {
    display: none;
    position: absolute;
    left: 0;
    top: 0;
}

正如你所看到的..在UL中它工作得很好,但在行上悬停图像显示错误,现在我使用固定大小但在最终应用程序中我将有几个图像大小

Thnks!

1 个答案:

答案 0 :(得分:0)

尝试使用 Bootstrap的偏移类

class="col-sm-4 text-center"

或使用 margin:0 auto;

// CSS
.centered {
   margin: 0 auto;
}


// HTML
<div class="container">
   <div class="centered text-center">
       centered content, wrapper for images (img-swap2)
   </div>
</div>

如果您将float: none;添加到.centered,它也将保留在Bootstrap网格中。