我有一个包含带有水平滚动条图像的单行表,并且我想使用鼠标滚轮水平滚动图像。
这是我的HTML。
<div class="container">
<div class="image-gallery">
<table>
<tr>
<td class="images">
<div class="img"><img src="../Images/small_Image_1.jpg" /><div class="description"><a class="image-slider-studets-names" href=" ">Alia Bhatt</a></div> </div>
</td>
<td class="images">
<div class="img"><img src="../Images/small_Image_2.jpg" /><div class="description"><a class="image-slider-studets-names" href="">sonia gandhi</a></div> </div>
</td>
<td class="images">
<div class="img"><img src="../Images/small_Image_3.jpg" /><div class="description"><a class="image-slider-studets-names" href="">Barney Stinson</a></div> </div>
</td>
<td class="images">
<div class="img"><img src="../Images/small_Image_4.jpg" /><div class="description"><a class="image-slider-studets-names" href="">Ranjit Choudary</a></div> </div>
</td>
<td class="images">
<div class="img"><img src="../Images/small_Image_5.jpg" /><div class="description"><a class="image-slider-studets-names" href="">Gangadhar Shastri</a></div> </div>
</td>
<td class="images">
<div class="img"><img src="../Images/small_Image_6.jpg" /><div class="description"><a class="image-slider-studets-names" href="">Mountain</a></div> </div>
</td>
</tr>
</table>
</div>
</div>
最佳答案
您可以使用Mouse Wheel(jQuery插件)来实现水平滚动。
鼠标滚轮提供了两个名为mousewheel
和unmousewheel
的帮助器方法,它们与jQuery中的其他事件帮助器方法一样工作,您的代码应如下所示:
<div class="container">
<div class="image-gallery">
<table>
<tr>
<td class="images">
<div class="img"><img src="../Images/small_Image_1.jpg" /><div class="description"><a class="image-slider-studets-names" href=" ">Alia Bhatt</a></div> </div>
</td>
<td class="images">
<div class="img"><img src="../Images/small_Image_2.jpg" /><div class="description"><a class="image-slider-studets-names" href="">sonia gandhi</a></div> </div>
</td>
<td class="images">
<div class="img"><img src="../Images/small_Image_3.jpg" /><div class="description"><a class="image-slider-studets-names" href="">Barney Stinson</a></div> </div>
</td>
<td class="images">
<div class="img"><img src="../Images/small_Image_4.jpg" /><div class="description"><a class="image-slider-studets-names" href="">Ranjit Choudary</a></div> </div>
</td>
<td class="images">
<div class="img"><img src="../Images/small_Image_5.jpg" /><div class="description"><a class="image-slider-studets-names" href="">Gangadhar Shastri</a></div> </div>
</td>
<td class="images">
<div class="img"><img src="../Images/small_Image_6.jpg" /><div class="description"><a class="image-slider-studets-names" href="">Mountain</a></div> </div>
</td>
</tr>
</table>
</div>
</div>
<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js?ver=1.3.2'></script>
<script type='text/javascript' src='/js/jquery.mousewheel.min.js'></script>
<script>
$(document).ready(function(){
$("body").mousewheel(function(event, delta) {
//The "30" represents speed. preventDefault ensures the page won't scroll down.
this.scrollLeft -= (delta * 30);
event.preventDefault();
});
});
</script>
这是一个DEMO Fiddle
关于jquery - 在鼠标滚轮上水平滚动,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27685085/