摘要:需要实现的效果如下图总是显示最新一个年份的列表,每次显示个年份列的列表手机个手机显示如下列表上鼠标也可以切换,两个箭头同样可以切换。
需要实现的效果如下图:
总是显示最新一个年份的列表,每次显示10个年份列的列表(手机4个)
手机显示如下:
列表上鼠标也可以切换,两个箭头同样可以切换。
Js:
</>复制代码
/---------------------------------------- 企业大事件 --------------------------------------------------/
</>复制代码
function big_event() {
var IsMove = false; //是否移动的标志位
var num = 10; // 默认显示年份的数量
var $title = $(".eh-year-move ul li"); //Title选取
var t_length = $title.length; //目前已有年份的数量
var t_width = $title.width() + 1; //单个title的宽度
var $content = $(".eh-content div.eh-content-item"); //年份对应的事件
var $move_ul = $(".eh-year-move ul"); //整个可移动的Title
var $y_line = $(".on-year-line"); //年份刻度
//console.log(n_index);
var winWidth = $(window).width(); //浏览器的宽度
if( winWidth <= 550 ){
num = 4;
}
else{
num = 10;
}
var i = t_length - num; //被隐藏年份的个数
//第一个title的li距离最左侧的距离
var d = ( $(".eh-year-wrap").width() - num * t_width ) / 2.0 ;
if( t_length >= num ){
//默认显示最新的年份列表
$title.eq( t_length -1 ).addClass("on-year").siblings().removeClass("on-year");
$content.eq( t_length -1 ).addClass("eh-content-item-on").siblings().removeClass("eh-content-item-on");
$move_ul.animate({
"left": - t_width * ( t_length - num ) ,
});
$y_line.animate({
"width": d + t_width * ( num - 0.5 ) ,
},0);
}
var n_index = $("li.on-year").index(); //当前显示年份的索引值
//console.log(n_index);
//鼠标划过切换内容
$title.hover(function() {
var index = $(this).index();
n_index = index;
tabMove(n_index); //引用主函数
});
//左箭头切换
$(".eh-arrowL").click(function() {
if( n_index > 0){
n_index -= 1;
if( ( ( n_index > ( num - 1 ) ) && IsMove ) || n_index < i ){
i -= 1;
}
tabMove(n_index); //引用主函数
}
});
//右箭头切换
$(".eh-arrowR").click(function() {
if( n_index < t_length - 1){
n_index += 1;
if( ( n_index > ( num - 1 + i ) ) && IsMove ){
i += 1;
}
tabMove(n_index); //引用主函数
}
});
//主函数
function tabMove(index){
$title.eq(index).addClass("on-year").siblings().removeClass("on-year");
$content.eq(index).addClass("eh-content-item-on").siblings().removeClass("eh-content-item-on");
//console.log(index);
//console.log(i);
if( index >= ( num - 1 + i ) ){
if( IsMove ){
$move_ul.animate({
"left": - t_width * ( index - num + 1 ) ,
});
}
$y_line.animate({
"width": d + t_width * ( num - 0.5 ),
},0);
if( i >= t_length - num ){
IsMove = false;
//console.log(IsMove);
}
}
else{
if(i >= 0 ){
if( index <= i ){
IsMove = true;
$move_ul.animate({
"left": - t_width * ( index ) ,
});
$y_line.animate({
"width": d + t_width * 0.5,
},0);
}
else{
index = index - i;
$y_line.animate({
"width": d + t_width * ( index + 0.5 ),
},0);
}
}
else{
$y_line.animate({
"width": d + t_width * ( index + 0.5 ),
},0);
}
}
}
};
$(document).ready(function(e) {
big_event(); //企业大事件
}).resize(function(){
big_event(); //企业大事件
});
HTML:
< div class="contain-contain"> < div class="eh-title">
</>复制代码
< div class="eh-year-wrap">
-
- 2005
-
- 2006
-
- 2007
-
- 2008
-
- 2009
-
- 2010
-
- 2011
-
- 2012
-
- 2013
-
- 2014
-
- 2015
-
- 2016
-
CSS:
</>复制代码
.event-history li{margin-bottom:0;}
- .event-history .eh-title{
- position:relative;
- float:left;
- width:100%;
- height:74px;
- }
- .eh-year-wrap{
- width:90%;
- margin:0 5% 0 5%;
- margin-top:30px;
- height:41px;
- border-top:solid 2px #b4b4b4;
- }
- .eh-year-move{
- position:relative;
- width:600px;
- height:30px;
- margin:7px auto 1px auto;
- overflow:hidden;
- }
- .eh-year-wrap ul{
- position:absolute;
- width:20000px;
- height:30px;
- left:0;
- top:0;
- }
- .eh-year-wrap ul li{
- float:left;
- width:59px;
- margin-right:1px;
- line-height:30px;
- text-align:center;
- cursor:pointer;
- }
- .eh-year-wrap ul li:hover,.eh-year-wrap ul li.on-year{color:#fff;background-color:#f75c5c;}
- .eh-arrow{
- position:absolute;
- display:block;
- width:62px;
- height:62px;
- top:0;
- background:url(../images/modules/aboutus/us_arrow.png) no-repeat;
- cursor:pointer;
- }
- .eh-arrowL{left:0;background-position:0 0;}
- .eh-arrowL:hover{background-position:0 -62px;}
- .eh-arrowR{right:0;background-position:-62px 0;}
- .eh-arrowR:hover{background-position:-62px -62px;}
- .on-year-line{
- display:block;
- position:absolute;
- width:600px;
- height:15px;
- left:5%;
- top:26px;
- border-right:solid 1px #f75c5c;
- }
- .eh-line-bg{
- display:block;
- width:100%;
- height:2px;
- margin-top:4px;
- background-color:#f75c5c;
- }
- .eh-content{
- float:left;
- width:90%;
- margin:30px 5% 0 5%;
- border-top:solid 1px #ebebeb;
- }
- .eh-content-item{
- display:none;
- float:left;
- width:100%;
- height:auto;
- }
- .eh-content-item-on{display:block;}
- .eh-content-item ul li{
- float:left;
- width:100%;
- height:50px;
- line-height:50px;
- text-indent:18px;
- border-bottom:solid 1px #ebebeb;
- word-break:keep-all;
- white-space:nowrap;
- overflow:hidden;
- text-overflow:ellipsis;
- }
- .eh-content-item ul li a:hover{text-decoration:underline;color:#f75c5c;}
文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。
转载请注明本文地址:https://www.ucloud.cn/yun/87634.html
摘要:本文整理了年月国产数据库大事件和重要产品发布消息。柏睿数据库加速安全卡面向全球重磅发布。月日,在全球数字经济大会成果发布会上,中国移动北京分公司与国产数据库领域新锐企业柏睿数据签署战略合作协议。本次大赛主要面向全国爱好数据库的高校学生。 本文整理了2021年8月国产数据库大事件和重要产品发布消息。目录8月国产数据库大事记TOP108月国产数据库大事记时间线产品/版本发布兼容认证8月排行榜新增...
摘要:自年起成为核心开发者之一,荣获年的弗兰克威利森纪念奖。目前供职于微软,负责的插件项目。的创始人,被称为之父,长期领导社区的发展,直到此次的退位风波。注弗兰克威利森纪念奖,即,该奖由出版集团设立,颁布给为社区做了突出贡献的个人。 showImg(https://segmentfault.com/img/bVbolDs?w=4469&h=3192); 春节假期结束了,大家陆续地重回到原来的...
摘要:自年起成为核心开发者之一,荣获年的弗兰克威利森纪念奖。目前供职于微软,负责的插件项目。的创始人,被称为之父,长期领导社区的发展,直到此次的退位风波。注弗兰克威利森纪念奖,即,该奖由出版集团设立,颁布给为社区做了突出贡献的个人。 showImg(https://segmentfault.com/img/bVbolDs?w=4469&h=3192); 春节假期结束了,大家陆续地重回到原来的...
阅读 3673·2021-10-09 09:41
阅读 2822·2021-10-08 10:18
阅读 2277·2021-09-10 10:51
阅读 2759·2021-09-10 10:50
阅读 914·2021-09-09 09:33
阅读 3498·2021-09-06 15:14
阅读 3134·2019-08-30 11:06
阅读 3348·2019-08-29 14:04