html纵向轮播图,jquery实现垂直无限轮播的方法分析

本文实例讲述了jquery实现垂直无限轮播的方法。分享给大家供大家参考,具体如下:

javascript垂直轮播,依赖于jquery实现的,并且首尾无缝衔接。原理很简单,就不讲述了,直接贴源码。

1.HTML节点

2.CSS样式

body{

margin:0;

padding: 0;

}

.banner_group{

width: 300px;

height: 500px;

overflow: hidden;

position: relative;

}

.scrollPageBtn{

width: 30px;

height: 100%;

position: absolute;

top: 0;

left: 40%;

background-color: #b2b2b2;

opacity: 0.2;

}

ul{

list-style: none;

width: 100%;

height: 100%;

margin: 0;

padding: 0;

position: relative;

}

ul li{

width: 100%;

height: 100%;

color: white;

font-size: 25px;

}

3.JQuery准备

4.JavaScript代码

var index = 0; // 保存当前所在项

/* 是否允许点击滑动动画,如果正在执行动画的过程中,

则禁止点击,如果动画完成后,则允许点击,

避免由于连点,出现画面不正常问题. */

var allowClick = true; //

// 页面加载完成后调用

$(function(){

index = 1; // 初始显示第2项

/* 注意:第一项是用来缓存末项的,实现无缝连接准备的,所以最开始显示的应该是第2项 */

$("#banner").css("bottom", "500px"); // 准备初始显示项

// 上一页

$("#last").on("click", function(){

if(allowClick){

allowClick = false;

index--; // 上一页,--

// 如果已经到了最开始过后,动画完成后,定位到末项

if(index == 0){

$("#banner").animate({bottom: (index * 500) + 'px'}, "fast", "swing", function () {

index = 4;

$("#banner").css("bottom", "2000px"); // 定位到末项

allowClick = true;

});

}else{

$("#banner").animate({bottom: (index * 500) + 'px'}, "fast", "swing", function () {

allowClick = true;

});

}

}

});

// 下一页

$("#next").on("click", function(){

if(allowClick){

allowClick = false;

if(index <= 5){

index ++; // 下一页++

if(index == 5){

$("#banner").animate({bottom: (index * 500) + 'px'}, "fast", "swing", function () {

index = 1;

$("#banner").css("bottom", "500px");

allowClick = true;

});

}else{

$("#banner").animate({bottom: (index * 500) + 'px'}, "fast", "swing", function () {

allowClick = true;

});

}

}

}

});

});

希望本文所述对大家jQuery程序设计有所帮助。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是使用jQuery实现纵向轮播图的代码: HTML代码: ```html <div class="slider"> <ul class="img_left"> <li><img src="img/1.jpg" alt=""></li> <li><img src="img/2.jpg" alt=""></li> <li><img src="img/3.jpg" alt=""></li> <li><img src="img/4.jpg" alt=""></li> </ul> <ul class="right_text"> <li class="currentStyle">1</li> <li>2</li> <li>3</li> <li>4</li> </ul> </div> ``` CSS代码: ```css .slider { width: 500px; height: 300px; overflow: hidden; position: relative; } .img_left { position: absolute; top: 0; left: 0; width: 500px; height: 1200px; margin: 0; padding: 0; } .img_left li { list-style: none; width: 500px; height: 300px; display: none; } .img_left li:first-child { display: block; } .right_text { position: absolute; top: 0; right: 0; width: 50px; height: 300px; margin: 0; padding: 0; } .right_text li { list-style: none; width: 50px; height: 50px; text-align: center; line-height: 50px; background-color: #ccc; margin-bottom: 10px; cursor: pointer; } .right_text li.currentStyle { background-color: #f00; } ``` JavaScript代码: ```javascript $(document).ready(function() { var index = 0; var timer = null; // 鼠标悬停在数字上时 $(".right_text li").mouseover(function() { clearInterval(timer); index = $(this).index(); $(this).addClass("currentStyle").siblings().removeClass("currentStyle"); $(".img_left li").eq(index).fadeIn().siblings().fadeOut(); }); // 鼠标离开时 $(".slider").mouseout(function() { timer = setInterval(function() { index++; if (index > 3) { index = 0; } $(".right_text li").eq(index).addClass("currentStyle").siblings().removeClass("currentStyle"); $(".img_left li").eq(index).fadeIn().siblings().fadeOut(); }, 2000); }).trigger("mouseout"); }); ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值