猿问

如何在 JavaScript 中的活动图像滑块的左侧和右侧包含尖括号

我有一个简单的图像滑块,如下面的小提琴所示,当有更多图像要显示时,单击活动图像即可滑动。

如何在活动图像的左侧和右侧添加尖括号,以告知用户并使用户能够在图像之间进行转换?

我还想确保当没有更多幻灯片可以过渡到左侧或右侧时,尖括号不会显示。

我能够在图像上包含箭头,但无法让它们执行与单击下一个或上一个图像时触发幻灯片更改相同的操作。

谢谢您的帮助。


喵喔喔
浏览 70回答 1
1回答

jeck猫

您好,请尝试以下更改:<div id="Arrows">G-Money Send Money&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <i id="Prev" onclick="changeSlide('prev');"class=" fa fa-chevron-left fa-3x" aria-hidden="true"></i>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <i id="Next" onclick="changeSlide('next');"class=" fa fa-chevron-right fa-3x" aria-hidden="true"></i>&nbsp; &nbsp; &nbsp; &nbsp; </div></div>你的 javascript 函数应该是这样的:<script>$(document).ready(function() {&nbsp; let $slider = $(".sliderG");&nbsp; let sliderItem = $slider.children(".item.active");&nbsp; let i = $slider.children(".item");&nbsp; //let i2 = $slider.children("#prev");&nbsp; let ind = 0;&nbsp; $slider&nbsp; &nbsp; .children(".item")&nbsp; &nbsp; .each(function() {&nbsp; &nbsp; &nbsp; $(this).attr("data-index", ind++);&nbsp; &nbsp; });&nbsp; i.on("click", function(e) {&nbsp; &nbsp; const that = $(this);&nbsp; &nbsp; let dataIndex = that.data("index");&nbsp; &nbsp; //alert(dataIndex);&nbsp; &nbsp; $(".item").removeClass("active");&nbsp; &nbsp; that.addClass("active");&nbsp; });});&nbsp; &nbsp; function changeSlide(n) {&nbsp; &nbsp; &nbsp; $('#Next').css("display", "block");&nbsp; &nbsp; &nbsp; $('#Prev').css("display", "block");&nbsp; &nbsp; &nbsp; let $slider = $(".sliderG");&nbsp; &nbsp; &nbsp; //console.log(n);&nbsp; &nbsp; &nbsp; var len = $slider.children(".item").length;&nbsp; &nbsp; &nbsp; if(n == 'prev'){&nbsp; &nbsp; &nbsp; &nbsp;//alert(n);&nbsp; &nbsp; &nbsp; &nbsp; var sliderItem = $slider.children(".item.active").prev();&nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; else {&nbsp; &nbsp; &nbsp; &nbsp; var sliderItem = $slider.children(".item.active").next();&nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; let index = sliderItem.data("index");&nbsp; &nbsp; &nbsp; if(index != undefined) {&nbsp; &nbsp; &nbsp; &nbsp; //alert(index);&nbsp; &nbsp; &nbsp; &nbsp; $(".item").removeClass("active");&nbsp; &nbsp; &nbsp; &nbsp; sliderItem.addClass("active");&nbsp; &nbsp; &nbsp; &nbsp; if(index == 0) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $('#Prev').css("display", "none");&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; else if(index == len-1) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $('#Next').css("display", "none");&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; }&nbsp;&nbsp; &nbsp; }</script>
随时随地看视频慕课网APP

相关分类

Html5
我要回答