Jquery 单击“上一页”按钮将抛出一个空白页
当我点击上一个广告按钮时,它会显示一个空白区域,有人可以显示来修复它吗?我不知道你是否能理解我在寻找什么。我在下面分享一个到输出的实时链接,当我一直点击上一个广告按钮时,你会理解我的观点 这是输出 这是密码Jquery 单击“上一页”按钮将抛出一个空白页,jquery,Jquery,当我点击上一个广告按钮时,它会显示一个空白区域,有人可以显示来修复它吗?我不知道你是否能理解我在寻找什么。我在下面分享一个到输出的实时链接,当我一直点击上一个广告按钮时,你会理解我的观点 这是输出 这是密码 $('.slider').each(function () { // For every slider var $this = $(this); // Current slider var $group = $this.find('.slide-group'); // Ge
$('.slider').each(function () { // For every slider
var $this = $(this); // Current slider
var $group = $this.find('.slide-group'); // Get the slide-group (container)
var $slides = $this.find('.slide'); // Create jQuery object to hold all slides
var currentIndex = 0; // Hold index number of the current slide
var timeout; // Sets gap between auto-sliding
$imageButton = $('.image-button');
// Remove in State after first
$.each($slides, function (index) {
$imageButton.eq(index + 1).addClass('inactive');
});
function move(newIndex) { // Creates the slide from old to new one
var animateLeft, slideLeft; // Declare variables
advance(); // When slide moves, call advance() again
// If it is the current slide / animating do nothing
if ($group.is(':animated') || currentIndex === newIndex) {
return;
}
// Add / Remove Active Class
$imageButton.eq(currentIndex).addClass('inactive');
$imageButton.eq(newIndex).removeClass('inactive');
if (newIndex > currentIndex) { // If new item > current
slideLeft = '100%'; // Sit the new slide to the right
animateLeft = '-100%'; // Animate the current group to the left
} else { // Otherwise
slideLeft = '-100%'; // Sit the new slide to the left
animateLeft = '100%'; // Animate the current group to the right
}
// Position new slide to left (if less) or right (if more) of current
$slides.eq(newIndex).css({
left: slideLeft,
display: 'block'
});
$group.animate({
left: animateLeft
}, function () { // Animate slides and
$slides.eq(currentIndex).css({
display: 'none'
}); // Hide previous slide
$slides.eq(newIndex).css({
left: 0
}); // Set position of the new item
$group.css({
left: 0
}); // Set position of group of slides
currentIndex = newIndex; // Set currentIndex to the new image
});
}
function advance() { // Used to set
clearTimeout(timeout); // Clear previous timeout
timeout = setTimeout(function () { // Set new timer
if (currentIndex < ($slides.length - 1)) { // If slide < total slides
move(currentIndex + 1); // Move to next slide
} else { // Otherwise
move(0); // Move to the first slide
}
}, 4000); // Milliseconds timer will wait
}
// image buttons
function imgBut() {
$.each($slides, function (index) {
$('#image-button-' + (index + 1)).on('click', function () {
move(index);
});
});
}
// arrows
function initArrow() {
$('#right-arrow').on('click', function () {
if (currentIndex < ($slides.length - 1)) { // If slide < total slides
move(currentIndex + 1); // Move to next slide
} else { // Otherwise
move(0); // Move to the first slide
}
})
$('#left-arrow').on('click', function () {
if (currentIndex === 0) { // If slide = first slide
move(3);
}else { // Otherwise
move(currentIndex - 1);
}
})
}
advance(); // Script is set up, advance() to move it
imgBut(); // init image buttons
initArrow(); //init arrows
});
$('.slider')。每个(函数(){//用于每个滑块
var$this=$(this);//当前滑块
var$group=$this.find('.slide group');//获取幻灯片组(容器)
var$slides=$this.find('.slide');//创建jQuery对象以保存所有幻灯片
var currentIndex=0;//保留当前幻灯片的索引号
var timeout;//设置自动滑动之间的间隔
$imageButton=$('.image button');
//在第一次之后以状态移除
$。每个($幻灯片,功能(索引){
$imageButton.eq(索引+1).addClass('inactive');
});
函数move(newIndex){//创建从旧幻灯片到新幻灯片的幻灯片
var animateLeft,slideLeft;//声明变量
advance();//当幻灯片移动时,再次调用advance()
//如果是当前幻灯片/动画,则不执行任何操作
如果($group.is(':animated')| | currentIndex===newIndex){
返回;
}
//添加/删除活动类
$imageButton.eq(currentIndex).addClass('inactive');
$imageButton.eq(newIndex).removeClass('inactive');
if(newIndex>currentIndex){//if new item>current
slideLeft='100%';//将新幻灯片放在右边
animateLeft='-100%';//向左设置当前组的动画
}否则{//
slideLeft='-100%';//将新幻灯片放在左边
animateLeft='100%';//向右设置当前组的动画
}
//将新滑块置于当前位置的左侧(如果较少)或右侧(如果较多)
$slides.eq(newIndex.css)({
左:slideLeft,
显示:“块”
});
$group.animate({
左:animateLeft
},函数(){//设置幻灯片动画和
$slides.eq(currentIndex).css({
显示:“无”
});//隐藏上一张幻灯片
$slides.eq(newIndex.css)({
左:0
});//设置新项目的位置
$group.css({
左:0
});//设置幻灯片组的位置
currentIndex=newIndex;//将currentIndex设置为新映像
});
}
函数advance(){//用于设置
clearTimeout(超时);//清除以前的超时
timeout=setTimeout(函数(){//设置新计时器
if(currentIndex<($slides.length-1)){//if slide<总幻灯片数
移动(currentIndex+1);//移动到下一张幻灯片
}否则{//
移动(0);//移动到第一张幻灯片
}
},4000);//计时器将等待毫秒
}
//图像按钮
函数imgBut(){
$。每个($幻灯片,功能(索引){
$(“#图像按钮-”+(索引+1))。在('click',函数(){
移动(索引);
});
});
}
//箭
函数initArrow(){
$(“#右箭头”)。在('click',函数(){
if(currentIndex<($slides.length-1)){//if slide<总幻灯片数
移动(currentIndex+1);//移动到下一张幻灯片
}否则{//
移动(0);//移动到第一张幻灯片
}
})
$('#左箭头')。在('click',函数(){
如果(currentIndex==0){//如果幻灯片=第一张幻灯片
移动(3);
}否则{//
移动(当前索引-1);
}
})
}
advance();//脚本已设置,advance()将其移动
imgBut();//初始化图像按钮
initArrow();//init arrows
});
它会不会像回到上一张图像而不是显示空白?也可以添加默认的静态图像或类似的东西
谢谢尝试:
if(currentIndex==0){move(2);
3图像索引为0,1,2.:)尝试:if(currentIndex==0){move(2);
3图像索引为0,1,2.:)