html图片快速轮播特效代码,轻松实现javascript图片轮播特效

本文实例介绍了javascript图片轮播特效的详细代码以及实现思路,分享给大家供大家参考,具体内容如下

还是先来看一看效果图:

具体代码:

一、HTML代码分析

此效果的层次结构比较清楚:

1. class为data的div是最外层的容器,可以用来控制整个效果图显示的位置。

2. id为content的ul用来存放左侧滚动的图片。

3. id为indicator的ul用来显示右侧的指示栏。

二、CSS代码

*{margin: 0; padding: 0;}

img{

border:0;

}

.dota{

width:570px;

height: 230px;

margin:100px auto;

position: relative;

overflow: hidden;

}

.dota #content{

float: left;

list-style: none;

position: absolute;

width:380px;

height:230px;

}

.dota #content img{

width:380px;

height:230px;

}

.dota #indicator{

float: right;

list-style: none;

width:180px;

height:220px;

padding: 5px;

background-color: #100F13;

}

.dota #indicator li{

width: 180px;

height: 44px;

background: url(images/anniu.png) 0 -44px;

}

.dota #indicator li.current{

background-position: 0 0;

}

.dota #indicator li a{

display: block;

width: 160px;

height: 34px;

padding: 5px 0 5px 25px;

}

.dota #indicator li a:link , .dota #indicator li a:visited{

text-decoration: none;

color: #686477;

font: 12px/145% "宋体";

}

这里,我对indicator中li的代码进行说明:

.dota #indicator li中的css代码就是设置右侧指示栏中的每一项,注意到,这里使用了background属性,也就是说li的背景是一张图片。准备好的图片如下:

322d03c1873b329580e638fe2e697ae7.png

这张准备好的图片大小为 180 * 88, 而.dota #indicator li中的background属性设置的position属性大小为 0 -44px, 即截取的图片的下半部分;所以indicator中所有的背景图片显示的是下半部分比较暗的部分; 而.dota #indicator li.current 的position属性大小为 0 0,所以默认情况下indicator的第一个显示高亮,其余的显示为暗黑的那部分。然后通过JQuery代码控制current属性作用在 "谁" 身上来切换选中状态。

三、JQuery代码

$(function(){

var nowImage = 0;

/* 为定时动画服务 */

$(".dota #content li").first().clone().appendTo($(".dota #content"));

var timer = setInterval(autoAnimate, 1500);

$(".dota").mouseenter(function(){

clearInterval(timer);

}).mouseleave(function(){

timer = setInterval(autoAnimate, 1500);

});;

$(".dota #indicator li").mouseenter(function(){

$(this).addClass("current").siblings().removeClass("current");

nowImage = $(this).index();

/*stop() 可以立刻清楚以前的动画,防止动画叠加*/

$(".dota #content").stop().animate({"top": -230 * nowImage}, 1000);

});

function autoAnimate(){

if(nowImage == 4){

nowImage = 0;

$(".dota #indicator li").eq(nowImage).addClass("current").siblings().removeClass("current");

$(".dota #content").stop().animate({"top":-230 * 5}, 1000,function(){

$(".dota #content").css("top",0);

});

}

else{

nowImage++;

$(".dota #content").stop().animate({"top": -230 * nowImage}, 1000);

$(".dota #indicator li").eq(nowImage).addClass("current").siblings().removeClass("current");

}

}

});

以上就是轻松实现javascript图片轮播特效的详细代码,希望对大家的学习有所帮助。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
jQuery实现图片特效可以通过手动点击来实现,具体方法如下: 1. HTML结构:需要一个容器元素来包裹图片和按钮,并在其中设置两个元素用于显示当前图片和按钮。 ```html <div class="slider-wrap"> <div class="slider-container"> <img src="img1.jpg" alt=""> <img src="img2.jpg" alt=""> <img src="img3.jpg" alt=""> </div> <div class="slider-nav"> <span class="current"></span> <span></span> <span></span> </div> </div> ``` 2. CSS样式:设置容器元素的宽度和高度,并将图片和按钮元素设置为绝对定位,使其重叠在一起。 ```css .slider-wrap { position: relative; width: 600px; height: 400px; overflow: hidden; } .slider-container { position: absolute; top: 0; left: 0; width: 100%; height: 100%; } .slider-container img { display: none; width: 100%; height: 100%; } .slider-nav { position: absolute; bottom: 20px; left: 50%; transform: translateX(-50%); } .slider-nav span { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin: 0 10px; cursor: pointer; background-color: #ccc; } .slider-nav .current { background-color: #333; } ``` 3. jQuery代码:监听按钮元素的点击事件,并根据点击的按钮来切换图片和按钮状态。 ```javascript $(function() { var $container = $('.slider-container'); var $imgs = $container.find('img'); var $nav = $('.slider-nav'); var $dots = $nav.find('span'); var currentIndex = 0; // 显示当前图片和按钮 function showSlide(index) { $imgs.hide().eq(index).show(); $dots.removeClass('current').eq(index).addClass('current'); } // 点击按钮切换图片和按钮状态 $dots.click(function() { var index = $(this).index(); if (index !== currentIndex) { currentIndex = index; showSlide(currentIndex); } }); // 初始化,显示第一张图片和按钮 showSlide(currentIndex); }); ``` 通过以上方法,就可以实现一个基于jQuery手动点击的图片特效

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值