资讯专栏INFORMATION COLUMN

公司大事记-jQuery跟踪切换

Dean / 3029人阅读

摘要:需要实现的效果如下图总是显示最新一个年份的列表,每次显示个年份列的列表手机个手机显示如下列表上鼠标也可以切换,两个箭头同样可以切换。

需要实现的效果如下图:

总是显示最新一个年份的列表,每次显示10个年份列的列表(手机4个)

手机显示如下:

列表上鼠标也可以切换,两个箭头同样可以切换。

Js:

</>复制代码

  1. /---------------------------------------- 企业大事件 --------------------------------------------------/

  2. </>复制代码

    1. function big_event() {
    2. var IsMove = false; //是否移动的标志位
    3. var num = 10; // 默认显示年份的数量
    4. var $title = $(".eh-year-move ul li"); //Title选取
    5. var t_length = $title.length; //目前已有年份的数量
    6. var t_width = $title.width() + 1; //单个title的宽度
    7. var $content = $(".eh-content div.eh-content-item"); //年份对应的事件
    8. var $move_ul = $(".eh-year-move ul"); //整个可移动的Title
    9. var $y_line = $(".on-year-line"); //年份刻度
    10. //console.log(n_index);
    11. var winWidth = $(window).width(); //浏览器的宽度
    12. if( winWidth <= 550 ){
    13. num = 4;
    14. }
    15. else{
    16. num = 10;
    17. }
    18. var i = t_length - num; //被隐藏年份的个数
    19. //第一个title的li距离最左侧的距离
    20. var d = ( $(".eh-year-wrap").width() - num * t_width ) / 2.0 ;
    21. if( t_length >= num ){
    22. //默认显示最新的年份列表
    23. $title.eq( t_length -1 ).addClass("on-year").siblings().removeClass("on-year");
    24. $content.eq( t_length -1 ).addClass("eh-content-item-on").siblings().removeClass("eh-content-item-on");
    25. $move_ul.animate({
    26. "left": - t_width * ( t_length - num ) ,
    27. });
    28. $y_line.animate({
    29. "width": d + t_width * ( num - 0.5 ) ,
    30. },0);
    31. }
    32. var n_index = $("li.on-year").index(); //当前显示年份的索引值
    33. //console.log(n_index);
    34. //鼠标划过切换内容
    35. $title.hover(function() {
    36. var index = $(this).index();
    37. n_index = index;
    38. tabMove(n_index); //引用主函数
    39. });
    40. //左箭头切换
    41. $(".eh-arrowL").click(function() {
    42. if( n_index > 0){
    43. n_index -= 1;
    44. if( ( ( n_index > ( num - 1 ) ) && IsMove ) || n_index < i ){
    45. i -= 1;
    46. }
    47. tabMove(n_index); //引用主函数
    48. }
    49. });
    50. //右箭头切换
    51. $(".eh-arrowR").click(function() {
    52. if( n_index < t_length - 1){
    53. n_index += 1;
    54. if( ( n_index > ( num - 1 + i ) ) && IsMove ){
    55. i += 1;
    56. }
    57. tabMove(n_index); //引用主函数
    58. }
    59. });
    60. //主函数
    61. function tabMove(index){
    62. $title.eq(index).addClass("on-year").siblings().removeClass("on-year");
    63. $content.eq(index).addClass("eh-content-item-on").siblings().removeClass("eh-content-item-on");
    64. //console.log(index);
    65. //console.log(i);
    66. if( index >= ( num - 1 + i ) ){
    67. if( IsMove ){
    68. $move_ul.animate({
    69. "left": - t_width * ( index - num + 1 ) ,
    70. });
    71. }
    72. $y_line.animate({
    73. "width": d + t_width * ( num - 0.5 ),
    74. },0);
    75. if( i >= t_length - num ){
    76. IsMove = false;
    77. //console.log(IsMove);
    78. }
    79. }
    80. else{
    81. if(i >= 0 ){
    82. if( index <= i ){
    83. IsMove = true;
    84. $move_ul.animate({
    85. "left": - t_width * ( index ) ,
    86. });
    87. $y_line.animate({
    88. "width": d + t_width * 0.5,
    89. },0);
    90. }
    91. else{
    92. index = index - i;
    93. $y_line.animate({
    94. "width": d + t_width * ( index + 0.5 ),
    95. },0);
    96. }
    97. }
    98. else{
    99. $y_line.animate({
    100. "width": d + t_width * ( index + 0.5 ),
    101. },0);
    102. }
    103. }
    104. }
    105. };
    106. $(document).ready(function(e) {
    107. big_event(); //企业大事件
    108. }).resize(function(){
    109. big_event(); //企业大事件
    110. });

HTML:

< div class="contain-contain"> < div class="eh-title">

</>复制代码

  1. < div class="eh-year-wrap">
    • 2005
    • 2006
    • 2007
    • 2008
    • 2009
    • 2010
    • 2011
    • 2012
    • 2013
    • 2014
    • 2015
    • 2016

CSS:

</>复制代码

  1. .event-history li{margin-bottom:0;}

  2. .event-history .eh-title{
  3. position:relative;
  4. float:left;
  5. width:100%;
  6. height:74px;
  7. }
  8. .eh-year-wrap{
  9. width:90%;
  10. margin:0 5% 0 5%;
  11. margin-top:30px;
  12. height:41px;
  13. border-top:solid 2px #b4b4b4;
  14. }
  15. .eh-year-move{
  16. position:relative;
  17. width:600px;
  18. height:30px;
  19. margin:7px auto 1px auto;
  20. overflow:hidden;
  21. }
  22. .eh-year-wrap ul{
  23. position:absolute;
  24. width:20000px;
  25. height:30px;
  26. left:0;
  27. top:0;
  28. }
  29. .eh-year-wrap ul li{
  30. float:left;
  31. width:59px;
  32. margin-right:1px;
  33. line-height:30px;
  34. text-align:center;
  35. cursor:pointer;
  36. }

  37. .eh-year-wrap ul li:hover,.eh-year-wrap ul li.on-year{color:#fff;background-color:#f75c5c;}
  38. .eh-arrow{
  39. position:absolute;
  40. display:block;
  41. width:62px;
  42. height:62px;
  43. top:0;
  44. background:url(../images/modules/aboutus/us_arrow.png) no-repeat;
  45. cursor:pointer;
  46. }
  47. .eh-arrowL{left:0;background-position:0 0;}
  48. .eh-arrowL:hover{background-position:0 -62px;}
  49. .eh-arrowR{right:0;background-position:-62px 0;}
  50. .eh-arrowR:hover{background-position:-62px -62px;}

  51. .on-year-line{
  52. display:block;
  53. position:absolute;
  54. width:600px;
  55. height:15px;
  56. left:5%;
  57. top:26px;
  58. border-right:solid 1px #f75c5c;
  59. }
  60. .eh-line-bg{
  61. display:block;
  62. width:100%;
  63. height:2px;
  64. margin-top:4px;
  65. background-color:#f75c5c;

  66. }
  67. .eh-content{
  68. float:left;
  69. width:90%;
  70. margin:30px 5% 0 5%;
  71. border-top:solid 1px #ebebeb;
  72. }
  73. .eh-content-item{
  74. display:none;
  75. float:left;
  76. width:100%;
  77. height:auto;
  78. }
  79. .eh-content-item-on{display:block;}
  80. .eh-content-item ul li{
  81. float:left;
  82. width:100%;
  83. height:50px;
  84. line-height:50px;
  85. text-indent:18px;
  86. border-bottom:solid 1px #ebebeb;
  87. word-break:keep-all;
  88. white-space:nowrap;
  89. overflow:hidden;
  90. text-overflow:ellipsis;
  91. }
  92. .eh-content-item ul li a:hover{text-decoration:underline;color:#f75c5c;}

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/87634.html

相关文章

发表评论

0条评论

最新活动
阅读需要支付1元查看
<