怎么用jQuery代码实现选项联动轮播效果
今天小编给大家分享一下怎么用jQuery代码实现选项联动轮播效果的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下面我们一起来了解一下吧。

专注于为中小企业提供成都做网站、网站制作服务,电脑端+手机端+微信端的三站合一,更高效的管理,为中小企业掇刀免费做网站提供优质的服务。我们立足成都,凝聚了一批互联网行业人才,有力地推动了成百上千企业的稳健成长,帮助中小企业通过网站建设实现规模扩充和转变。
代码如下:
JQ轮播三级连锁
CSS
*{
border:none;
margin: 0;
padding: 0;
list-style: none;
outline: none;
}
html,body{
width: 100%;
height: 100%;
}
/*方法二*/
body{
display: flex;
align-items: center;/****水平居中****/
justify-content: center;/*垂直居中*/
}
.parent{
width: 750px;
height: 400px;
/*方法一*/
/*margin: 0 auto;*/
/*position: relative;*/
/*top: 50%;*/
/*margin-top: -200px;*/
}
/*轮播*/
.top p{
width: 90%;
margin: 0 auto;
}
.top p a{
display: inline-block;
line-height: 30px;
width: 23%;
padding: 10px 0;
text-align: center;
text-decoration: none;
border: 2px solid transparent;
color: slategray;
}
.top p a.selected{
border: 2px solid #e4393c;
color: #e4393c;
}
/*图片*/
.fours{
width: 650px;
margin: 0 auto;
height: 300px;
position: relative;
margin-top: 30px;
}
.fours a{
position: absolute;
}JS
定义变量和定时器,变量等价于eq(index)中index,自动轮播是可以的,关键在于,鼠标进入选项卡区域时候,怎么对应想要的轮播画面,
方法:停止定时器,获取当前选项卡下标,匹配对应的轮播画面显示出来。
var a=0;
var t=null;
$(function(){
$('.fours>a:not(:first-child)').hide();
t=setInterval("autoMove()",2000);
//鼠标进入轮播停止
$('.parent').hover(function(){clearInterval(t)},function(){t=setInterval("autoMove()",2000);});
// 当鼠标进去对应选项时候图片对应变化
$(".top p>a").hover(function(){
clearInterval(t);
var num=$(this).index();
showThis(num);
//console.log(num);
})
});
function autoMove(){
a++;
if(a>=4){
a=0;
}
play(a);
}
function play(a){
$('.fours>a').filter(":visible").fadeOut(500).parent().children().eq(a).fadeIn(1000);
$('.top p a').eq(a).addClass("selected").siblings().removeClass("selected");
}
//鼠标进入的情况
function showThis(sum){
$(".fours>a").eq(sum).fadeIn(1000).siblings().fadeOut(500);
$(".top p a").eq(sum).addClass("selected").siblings().removeClass("selected");
}以上就是“怎么用jQuery代码实现选项联动轮播效果”这篇文章的所有内容,感谢各位的阅读!相信大家阅读完这篇文章都有很大的收获,小编每天都会为大家更新不同的知识,如果还想学习更多的知识,请关注创新互联行业资讯频道。
网页题目:怎么用jQuery代码实现选项联动轮播效果
网页URL:http://www.jxjierui.cn/article/gghjpe.html


咨询
建站咨询
