gpt4 book ai didi

javascript - 我的旋转木马末尾出现空白区域

转载 作者:太空宇宙 更新时间:2023-11-04 04:42:26 25 4
gpt4 key购买 nike

我用过this script在我的网站上创建无限旋转木马here .它已使用 CSS 自定义,因此第一个和最后一个元素显示一半。

如果你一直点击向右箭头,你最终会在最后点击一个空白区域。到目前为止,我还无法解决这个问题。任何人都可以提供任何解决方案吗?

相关脚本如下:

/**
* @author Stéphane Roucheray
* @extends jquery
*/
jQuery.fn.simplecarousel = function(previous, next, options){
var sliderList = jQuery(this).children()[0];

if (sliderList) {
var increment = jQuery(sliderList).children().outerWidth(true),
elmnts = jQuery(sliderList).children(),
numElmts = elmnts.length,
sizeFirstElmnt = increment,
shownInViewport = Math.round(jQuery(this).width() / sizeFirstElmnt),
firstElementOnViewPort = 1,
isAnimating = false;

for (i = 0; i < shownInViewport; i++) {
jQuery(sliderList).css('width',(numElmts+shownInViewport)*increment + increment + "px");
jQuery(sliderList).append(jQuery(elmnts[i]).clone());
}

jQuery(previous).click(function(event){
if (!isAnimating) {
if (firstElementOnViewPort == 1) {
jQuery(sliderList).css('left', "-" + numElmts * sizeFirstElmnt + "px");
firstElementOnViewPort = numElmts;
}
else {
firstElementOnViewPort--;
}

jQuery(sliderList).animate({
left: "+=" + increment,
y: 0,
queue: true
}, "swing", function(){isAnimating = false;});
isAnimating = true;
}

});

jQuery(next).click(function(event){
if (!isAnimating) {
if (firstElementOnViewPort > numElmts) {
firstElementOnViewPort = 2;
jQuery(sliderList).css('left', "0px");
}
else {
firstElementOnViewPort++;
}
jQuery(sliderList).animate({
left: "-=" + increment,
y: 0,
queue: true
}, "swing", function(){isAnimating = false;});
isAnimating = true;
}
});
}
};

#home-carousel-container {
position: relative;
}
#home-carousel {
overflow: hidden;
}
#home-carousel ul {
margin-left: -143px;
padding: 0;
position: relative;
}
#home-carousel li {
float: left;
height: 645px;
list-style: none outside none;
margin: 0 3px;
width: 256px;
}

enter image description here

最佳答案

根据我的评论。

您在轮播上设置了一个负的左边距,导致它隐藏了一半的图像。结果,当您单击下一个/上一个时,它会显示图像移动到的位置以产生持续的影响。

在你的CSS中,我改变了

#home-carousel ul{
position: relative;
padding: 0;
margin-left: -143px;
}

#home-carousel ul{
position: relative;
padding: 0;
margin-left: -3px;
}

从来没有遇到过任何问题。

Screenshot of the page with the modification - In Chrome

关于javascript - 我的旋转木马末尾出现空白区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15204742/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com