水平图像滑块不工作在铬和IE11

时间:2015-11-10 17:58:14

标签: javascript html css html5 css3

我正在构建一个水平图像滑块,它在Chrome和IE11中无效。关于它的奇怪之处在于,当使用Chrome和IE时,它确实在小提琴中工作。

这是小提琴:https://jsfiddle.net/7y81hjtx/6/

这是在网上:http://a-b-smith.com/wedding/slider.html

注意右边的所有图像如何而不是滚动,变得非常微小以适应屏幕?

这是相关的HTML

<div class="galleryWrap" id="wrapper">
    <table border="0"> 
        <tbody>
            <tr>
                <td>
                    <div class="horizontalGalleryImageHolder">
                        <img id="1" src="http://lorempixel.com/200/200/" style="max-height: 390px;" />
                    </div>
                </td>
                <td>
                    <div class="horizontalGalleryImageHolder">
                        <img id="2" src="http://lorempixel.com/g/200/200/" style="max-height: 390px;" />
                    </div>
                </td>
                <td class="wide">
                    <div class="horizontalGalleryImageHolder">
                        <img id="3"src="http://lorempixel.com/400/200/sports/" style="max-height: 390px;" />
                    </div>
                </td>
                <td>
                    <div class="horizontalGalleryImageHolder">
                        <img id="4" src="http://lorempixel.com/200/200/sports/1/" style="max-height: 390px;" />
                    </div>
                </td>
                <td>
                    <div class="horizontalGalleryImageHolder">
                        <img id="5" src="http://lorempixel.com/200/200/" style="max-height: 390px;" />
                    </div>
                </td>
                <td>
                    <div class="horizontalGalleryImageHolder">
                        <img id="6" src="http://lorempixel.com/g/200/200/" style="max-height: 390px;" />
                    </div>
                </td>
                <td>
                    <div class="horizontalGalleryImageHolder">
                        <img id="7" src="http://lorempixel.com/200/200/sports/" style="max-height: 390px;" />
                    </div>
                </td>
                <td>
                    <div class="horizontalGalleryImageHolder">
                        <img id="8" src="http://lorempixel.com/200/200/sports/1/" style="max-height: 390px;" />
                    </div>
                </td>
                <td>
                    <div class="horizontalGalleryImageHolder">
                        <img id="9" src="http://lorempixel.com/200/200/" style="max-height: 390px;" />
                    </div>
                </td>
                <td>
                    <div class="horizontalGalleryImageHolder">
                        <img id="10" src="http://lorempixel.com/g/200/200/" style="max-height: 390px;" />
                    </div>
                </td>
                <td>
                    <div class="horizontalGalleryImageHolder">
                        <img id="11" src="http://lorempixel.com/200/200/sports/" style="max-height: 390px;" />
                    </div>
                </td>
                <td>
                    <div class="horizontalGalleryImageHolder">
                        <img id="12" src="http://lorempixel.com/200/200/sports/1/" style="max-height: 390px;" />
                    </div>
                </td>
            </tr> 
        </tbody>
    </table>
</div>

CSS

.ulWrapper {
margin: 20px auto 0;
display: block;
height: 50px;
}

.ulWrapper ul {
margin: 0 auto;
padding: 0;
display: table;
list-style: none;
}

.ulWrapper li {
float: left;
}
ul
{
list-style-type: none;
}

li{width: 50px; float: left; margin-right: 1px; margin-left: 1px;}
body {
    margin: 0;
}
table {
    border-collapse: collapse;
}
td.wide{width: 40%;}
td {
    width: 20%;
    padding: 0px;
}
img {
    width: 100%
}
.galleryWrap {
    width: 100%;
    overflow-x: scroll;
}
.left {
    float: left;
    width: 100px;
    height: 30px;
    background-color: blue;
    color: white;
}
.right {
    float: right;
    width: 100px;
    height: 30px;
    background-color: blue;
    color: white;
}

table {
    white-space: nowrap;
}
td {
    display: inline-block;
}

的Javascript

 function left() {
        var width = document.getElementById('wrapper').clientWidth;
        var offsetWidth = width / 5; 

        document.getElementById("wrapper").scrollLeft -= offsetWidth;
    }

    function right() {
        var width = document.getElementById('wrapper').clientWidth;
        var offsetWidth = width / 5;

        document.getElementById("wrapper").scrollLeft += offsetWidth;
    }

和JQuery(虽然我很肯定这没关系)

$('.small-img').click(function () {
    var id = $(this).attr('id');
    var idNum = id.charAt(1);
    if (id.charAt(2) == '0'){
        idNum = 10;
    }else if(id.charAt(2) == '1'){
       idNum = 11; 
    }else if(id.charAt(2) == '2'){
       idNum = 12; 
    }
    document.getElementById(idNum).scrollIntoView();
});

如何恢复滚动条并防止图像变小?

1 个答案:

答案 0 :(得分:1)

问题在于它不像100%宽度的图像。我删除了它,它开始工作:

img {
  width: 100%;
}

然后我用固定的100px宽度替换100%宽度,它仍然有用。

我不确定为什么会这样。也许浏览器不想尝试用%尺寸来解决什​​么问题?

希望这有帮助。