[英]Horizontal image slider not working in chrome and IE11
我正在构建水平图像滑块,但它无法在Chrome和IE11中使用。 关于它的怪异之处在于,它在使用Chrome和IE时确实可以发挥作用。
这是小提琴: https : //jsfiddle.net/7y81hjtx/6/
它在网上: http : //ab-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;
}
Java脚本
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();
});
如何恢复滚动条并防止图像变小?
问题是它不喜欢100%宽度的图像。 我删除了它,它开始工作:
img {
width: 100%;
}
然后,我将100%的宽度替换为固定的100px宽度,但仍然可以使用。
我不确定为什么会这样。 也许浏览器不喜欢尝试找出%大小会导致什么溢出?
希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.