<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>淡入淡出点击+定时轮播</title>
<script src="js/jquery-3.2.1.min.js" type="text/javascript" charset="utf-8"></script>
</head>
<style type="text/css">
*{margin: 0;padding: 0;}
#bac{width: 100%;height: 340px;background-color: lightgrey;position:relative;}
.pic_area{margin:0 auto;width: 790px;height: 340px;}
.pic_all{margin:0 auto;width: 790px;height: 340px;position:relative;}
.pic_2,.pic_3,.pic_4{position:absolute;top:0;}
.point{background-color: white;width:11px;height: 11px;border-radius: 50%;margin-left:14px;float:left;}
.point_all{position:absolute;top:320px;left:calc(50% - 43px);}
.clearfix:after{content:"."; display:block; height:0; clear:both; visibility:hidden;}
.point:hover{background-color: #999!important;}
.other{width: 100%;height: 20px;background-color: grey;}
</style>
<body>

<div id="bac">

<div class="pic_area">
<div class="pic_all">
<img class="pic pic_1" src="img/1.jpg"/>
<img class="pic pic_2" src="img/2.jpg"/>
<img class="pic pic_3" src="img/3.jpg"/>
<img class="pic pic_4" src="img/4.jpg"/>
</div>
<div class="point_all clearfix">
<div class="point point1"></div>
<div class="point point2"></div>
<div class="point point3"></div>
<div class="point point4"></div>
</div>
</div>
</div>
<div class="other">
</div>

<script type="text/javascript">

var count=0;
var timer;
var ul = document.getElementsByClassName('point_all');
var lis = document.getElementsByClassName('point');
for (var i = 0; i < lis.length; i++) {
lis[i].index = i;
lis[i].onclick = function () {
count=this.index;
};
}
//js的定时器,BOM
function start(){
timer=setInterval(function(){

var num = (count)%4;
$(".pic").eq(num).fadeIn(2000).siblings().fadeOut(2000);
$(".point").eq(num).css("background-color","#999").siblings().css("background-color","white");
count++;
},3000)
}

start();
$(".point").on("click",function (){
// $(".pic_all:nth-child(1)").fadeIn(1200).siblings().fadeOut(1200); 这里不能用siblings(),因为此时默认的选择器是$(".pic_all")
// if($(".pic").attr("style","opacity")){
// return false;
// } 有错误,会增加一个style opacity属性
$(".pic").eq(count).fadeIn(2000).siblings().fadeOut(2000); //$("p:eq(1)")括号内部只能是固定数字,$(".pic").eq(count)括号内部可以是变量
$(".point").eq(count).css("background-color","#999").siblings().css("background-color","white");
})

$(".pic_area").mouseenter(function stopInterval(){
clearInterval(timer);
}) //避开了连点问题,因为定时器会重启,而单纯的点击事件事件则不存在连点问题,或者说本身淡入淡出就不涉及连点问题

$(".pic_area").mouseleave(function restartInterval(){
start();
})

// $(".point2").on("click",function (){
// $(".pic_2").fadeIn(1200).siblings().fadeOut(1200);
// $(".point2").css("background-color","#999").siblings().css("background-color","white");
// })
</script>
</body>

</html>

将以上粘贴到前端开发工具中可以实现

//部分为注释

jq部分主要分为四块,分别为:

1,获取相应标签的index;

2,设置定时器,此时注意,将定时器放在函数内并赋给一个变量,变量需设为全局变量;

3,利用index去设置点击事件,此时应注意:eq()  .eq()的区别, .eq()括号内可以设变量,:eq()不能,设置变量可以提高可扩展性;

4,鼠标进入和离开事件,其中应注意 mouseover 对应mouseout 和 mouseenter 对应mouseleave的区别,可以搜索,不赘述;

图片自己随便加

以上

js+jq 淡入淡出轮播(点击+定时+鼠标进入移出事件)的更多相关文章

  1. js渐隐渐现透明度变化淡入淡出轮播图

    js渐隐渐现透明度变化淡入淡出轮播图.焦点图 一些广告banner展示常见. (附件) <!DOCTYPE html> <html> <head> <meta ...

  2. jQuery淡入淡出轮播图实现

    大家好我是 只是个单纯的小白,这是人生第一次写博客,准备写的内容是Jquery淡入淡出轮播图实现,在此之前学习JS写的轮播图效果都感觉不怎么好,学习了jQuery里的淡入淡出效果后又写了一次轮播图效果 ...

  3. jquery的fadeTo方法的淡入淡出轮播图插件

    由于对基于jquery的简单插件开发有了一定的了解,慢慢的也对基于jquery的插件开发有了兴趣,在上班结束之后就研究各种插件的思路逻辑.最近开发了一款基于jquery的fadeTo方法的轮播图插件, ...

  4. jq交叉淡入淡出轮播图

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

  5. js中用面向对象的思想——淡入淡出轮播图

    首先看下效果图 明确功能 1.前后切换(边界判断) 2.按键切换  3.自动轮播 css代码 <style> * {margin:0; padding:0;} li{list-style: ...

  6. jquery淡入淡出轮播图

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

  7. vue渐变淡入淡出轮播图

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

  8. 原生JS面向对象思想封装轮播图组件

    原生JS面向对象思想封装轮播图组件 在前端页面开发过程中,页面中的轮播图特效很常见,因此我就想封装一个自己的原生JS的轮播图组件.有了这个需求就开始着手准备了,代码当然是以简洁为目标,轮播图的各个功能 ...

  9. JS实现小图放大轮播效果

    JS实现小图放大轮播页面效果入下(图片为优行商旅页面照片): 实现效果:图片自动轮播,鼠标移入停止,移出继续轮播点击下方小图可以实现切换 步骤一:建立HTML布局,具体如下: <body> ...

随机推荐

  1. MySQL 如何更改某一用户及伞下成员的path

    MySQL  如何更改某一用户及伞下成员的path 在有的系统中,推荐关系的维护不只是pid那么简单,为了某些业务,可能还会需要维护path字段,path字段的存在,优点在于查询方便,最起码不用递归了 ...

  2. python 操作mongodb 文件相关

    https://api.mongodb.com/python/current/tutorial.html# 文档地址 from pymongo import MongoClientfrom gridf ...

  3. 解决:IDE编译报错:Dangling metacharacter

    Dangling metacharacter的意思是说:摇摆不定的元字符. 翻译成编程意思就是:当前字符计算有其它意思,并不能确定你到底用于什么意思.类似于中文的多义词. 如下图所示,当我们要分割字符 ...

  4. oa_mvc_easyui_登录完成(2)

    1.使用MVC特有的ajax方式:异步表单提交方式 js文件引用:<script src="~/Scripts/jquery.unobtrusive-ajax.min.js" ...

  5. ASP.NET配置KindEditor文本编辑器

    文本编辑器:CKEditor和CKFinder  KindEditor 1.KindEditor KindEditor 是一套开源的在线HTML编辑器,主要用于让用户在网站上获得所见即所得编辑效果,开 ...

  6. JVM(6)之 二次标记

    开发十年,就只剩下这套架构体系了! >>>   上一章我们讲到了标记,但是不是被标记了就肯定会被回收呢?不知道小伙伴们记不记得Object类有一个finalize()方法,所有类都继 ...

  7. Linux Exploit系列之四 使用return-to-libc绕过NX bit

    使用return-to-libc绕过NX bit 原文地址:https://bbs.pediy.com/thread-216956.htm 这篇讲解的比较好,主要的问题是获得system地址和exit ...

  8. D2. Kirk and a Binary String (hard version) D1 Kirk and a Binary String (easy version) Codeforces Round #581 (Div. 2) (实现,构造)

    D2. Kirk and a Binary String (hard version) time limit per test1 second memory limit per test256 meg ...

  9. Zookeeper客户端使用(使用Curator)

    Zookeeper客户端(使用Curator) 三.使用curator客户端 在pom.xml中加入依赖 <dependency> <groupId>org.apache.cu ...

  10. [uboot] (番外篇)uboot之fdt介绍 (转)

    以下例子都以project X项目tiny210(s5pv210平台,armv7架构)为例 [uboot] uboot流程系列:[project X] tiny210(s5pv210)上电启动流程(B ...