javascript - 当用户使用 vanilla javascript 单击右/左可单击图像时如何执行滚动机制

标签 javascript php html css

我有一个页面,我希望用户能够通过按右/左图像箭头向右/向左滚动。但我不确定如何将可点击图像连接到html的overflow-x机制以向右/向左滚动。

CSS 包含用户可以滚动的所有图像

.imgScroll{
margin: 0 auto;
width: 70%;
overflow-x: scroll;
overflow-x: hidden;
white-space:nowrap
}

.arrows{(clickable arrows, to scroll right/left)
position: absolute;
opacity: 0.5;
top: 20px;
cursor: pointer;
}

PHP,其中所有图像都设置为滚动框

(while loop execute do the following)
$childImg .= "<img src='../ProductImages/ChildImages/$childName' 
class='imgBotSize' onclick='openNav()'>";

HTML

<div id="botWrapper">
     <?php echo "<p1>" . $pDetails . "</p1>"?>
     <div id="imgBot">
         <div id="imgBoxBot">
             <div class="arrows" style="right: 180px">
                 <img src="../arrow-right.png" width="70px" height="70px">
              </div>
              <div class="arrows" style="left: 180px">
              <img src="../arrow-left.png" width="70px" height="70px">
               </div>
               <div class="imgScroll">
                    <?php echo $childImg;?>
                </div>
          </div>
      </div>
</div>

最佳答案

看起来您正在尝试创建图像轮播。

这里有一个漂亮的图像轮播:kenwheeler.github.io/slick您可以根据需要设置不同的选项来显示它。

关于javascript - 当用户使用 vanilla javascript 单击右/左可单击图像时如何执行滚动机制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45184923/

相关文章:

javascript - 上传并播放歌曲

javascript - 更新 d3 中的图表

javascript - 根据星期几激活选项卡

php - 仅在使用 PHPUnit 时找不到类

php - 页面加载时自动点击 iframe 中的按钮

html - 如何在没有滚动条的情况下一次在 html 页面中嵌入 pdf 文件?

javascript - jQuery slider 索引

javascript - 使用 JQuery 或 JavaScript 检查本地驱动器中的现有文件。

php - 是否有任何函数可以按相反顺序对数组进行排序?

iPhone:从网络应用程序访问相册