<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
*{
margin: 0;
padding: 0;
}
#box{
width:590px;
height: 470px;
position: relative;
border: 1px solid;
margin: 100px auto;
}
#imgList{
width: 590px;
height: 470px;
position: relative;
list-style: none;
}
#imgList li{
width: 590px;
height: 470px;
position: absolute;
top: 0;
left: 0;
display: none;
}
#num{
width: 590px;
height: 50px;
position: absolute;
bottom: 0;
left: 0;
background-color: #fdd;
line-height: 50px;
}
#num i{
display: inline-block;
width: 20px;
height: 20px;
margin: 0 10px;
background-color: #fff;
border-radius: 50%;
cursor: pointer;
}
#prve,#next{
width: 45px;
height: 100px;
background: pink;
position: absolute;
top: 0;
bottom: 0;
margin: auto;
color: #fff;
text-align: center;
line-height: 100px;
font-size: 30px;
cursor: pointer;
}
#next{
right: 0;
}
#box .on{
background-color:aquamarine;
}
</style>
</head>
<body>
<div id="box">
<ul id="imgList">
<li style="display: block;"><a href="#"><img src="img/1.jpg"></a></li>
<li><a href="#"><img src="img/2.jpg"></a></li>
<li><a href="#"><img src="img/3.jpg"></a></li>
<li><a href="#"><img src="img/4.jpg"></a></li>
</ul>
<div id="num">
<i class="on"></i>
<i></i>
<i></i>
<i></i>
</div>
<div id="prve"><</div>
<div id="next">></div>
</div> <script src="js/tools.js"></script>
<script>
var imgs = $("li"),//所有的照片
len = imgs.length,//照片的数量
currentIndex = 0,//默认显示第一张
nextIndex = 1,//下一张显示的照片
nums = $("i");//所有的小圆点
// 自动轮播
var timer = setInterval(move,2000);
// 鼠标移入自动轮播暂停
$("#box").onmouseenter = function(){
clearInterval(timer);
}
// 鼠标移出启动计时器进行自动轮播
$("#box").onmouseleave = function(){
timer = setInterval(move,2000);
}
// 定义图片运动的函数
function move(){
fadeOut(imgs[currentIndex],1000);
fadeIn(imgs[nextIndex],1000);
nums[currentIndex].className = "";
nums[nextIndex].className = "on";
currentIndex = nextIndex;
nextIndex++;
if(nextIndex === len)
nextIndex = 0;
}
// 单击上一个和下一个的事件
$("#prve").onclick = function(){
nextIndex = currentIndex-1;
if(nextIndex<0)
nextIndex = len-1;
move();

更多内容请见原文,文章转载自:https://blog.csdn.net/weixin_44519496/article/details/118599165

javascript写淡入淡出效果的轮播图的更多相关文章

  1. 用原生的javascript 实现一个无限滚动的轮播图

    说一下思路:和我上一篇博客中用JQ去写的轮播图有相同点和不同点 相同点: 首先页面布局是一样的 同样是改变.inner盒子的位置去显示不同的图片 不同点: 为了实现无限滚动需要多添加两张重复的图片 左 ...

  2. web常见效果之轮播图

    轮播图的展示效果是显而易见: HTML代码如下 <!DOCTYPE html> <html> <head> <meta charset="UTF-8 ...

  3. 针对淡入淡出的定时轮播效果js

    如果不使用jquery的fadeIn和fadeOut的接口和不适用animate情况下,如果要做用js实现淡入淡出轮播效果,我所想到的办法就是使用css3新特性transition(注意好兼容性). ...

  4. 首页大屏广告效果 jquery轮播图淡入淡出

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. javascript 图片淡入淡出效果 实例源代码

    代码说明:把代码粘贴好之后,需要更改html代码中的图片路径,即可执行成功.后面还有对js代码的详细说明,希望大家好好消化,好好理解. html源代码: <head> <title& ...

  6. vue 写一个炫酷的轮播图

    效果如上图: 原理: 1.利用css 的 transform 和一些其他的属性,先选五张将图片位置拍列好,剩余的隐藏 2.利用 js 动态切换类名,达到切换效果 css代码如下 .swiper-cer ...

  7. javascript编写的一个完整全方位轮播图效果

    1 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&q ...

  8. Jquery基础(动画效果的轮播图特效)

    jquery文档准备的三种写法: $(document).ready(function() { }); $().ready(function() { }); $(function() { }); jq ...

  9. 高仿阴阳师官网轮播图效果的jQuery插件

    代码地址如下:http://www.demodashi.com/demo/12302.html 插件介绍 这是一个根据阴阳师官网的轮播效果所扒下来的轮播插件,主要应用于定制个性化场景,目前源码完全公开 ...

随机推荐

  1. Blazor WebAssembly 渐进式 Web 应用程序 (PWA) 使用 LocalStorage 离线处理数据

    原文链接:https://www.cnblogs.com/densen2014/p/16133343.html Window.localStorage 只读的localStorage 属性允许你访问一 ...

  2. 【洛谷】P4555 [国家集训队]最长双回文串

    P4555 [国家集训队]最长双回文串 题源:https://www.luogu.com.cn/problem/P4555 原理:Manacher 还真比KMP好理解 解决最长回文串问题 转化为长度为 ...

  3. javaWeb代码整理03-druid数据库连接池

    jar包: maven坐标: <dependency> <groupId>com.alibaba</groupId> <artifactId>druid ...

  4. Python 一网打尽<排序算法>之堆排序算法中的树

    本文从树数据结构说到二叉堆数据结构,再使用二叉堆的有序性对无序数列排序. 1. 树 树是最基本的数据结构,可以用树映射现实世界中一对多的群体关系.如公司的组织结构.网页中标签之间的关系.操作系统中文件 ...

  5. Python学习-Day1(Typora软件与计算机)

    学习总括 Typora软件介绍(markdown语法) 相关拓展知识 文件的后缀名是什么? 什么是语言? 什么是编程语言? 什么是编程?(程序员写代码的本质) 计算机的五大组成部分 计算机的本质 计算 ...

  6. 单列集合(Collection-Set)

    (部分) Set类特点: "无序"(输入顺序和存储顺序不一样) HashSet 底层是HashMap 关于不能有重复元素/对象 遇到的问题: 解决办法:重新类的相关方法 选择名字和 ...

  7. 干货 | 手把手教你搭建一套OpenStack云平台

    1 前言 今天我们为一位朋友搭建一套OpenStack云平台. 我们使用Kolla部署stein版本的OpenStack云平台. kolla是用于自动化部署OpenStack的一个项目,它基于dock ...

  8. SICP 2.2: 层次性数据和闭包性质(Python实现)

    绪论 序对可以为我们提供用于构造复合数据的基本"粘接剂",鉴于Python中tuple中元素不可变的性质,我们通过list来实现序对,如[1, 2].Python的PyListOb ...

  9. 【python疫情可视化】用pyecharts开发全国疫情动态地图,效果酷炫!

    一.效果演示 我用python开发了一个动态疫情地图,首先看下效果: 如图所示,地图根据实时数据通过时间线轮播的方式,动态展示数据的变化.随着时间的推移,疫情确诊数量的增多,地图各个省份颜色逐渐加深, ...

  10. vue3中的四种插槽的介绍-保证让你看看的明明白白!

    插槽 当组件中只有一个插槽的时候,我们可以不设置 slot 的 name 属性. v-slot 后可以不带参数,但是 v-slot 在没有设置 name 属性的时候, 插槽口会默认为"def ...