JS如何模仿万科底部的新闻滑动特效

发布时间:2021-07-09 10:44:20 作者:小新
来源:亿速云 阅读:136

小编给大家分享一下JS如何模仿万科底部的新闻滑动特效,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!

具体代码如下所述:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>仿万科的底部的新闻滑动特效</title>
  <style>
    * {
      padding: 0;
      margin: 0;
    }
    #subject {
      position: relative;
      width: 80%;
      height: 165px;
      background: skyblue;
      margin: 200px auto;
      overflow: hidden;
    }
    #subject > ul > li {
      position: absolute;
      float: left;
      list-style: none;
      width: 40%;
      height: 165px;
      font-size: 48px;
      text-align: center;
      color: #fff;
      line-height: 165px;
      transition: 0.5s;
    }
    .item1 {
      background: orange;
      left: 0;
      z-index: 1;
    }
    /*hover:item1*/
    #subject.state-1 .item2,
    .item2 {
      background: deepskyblue;
      left: 40%;
      z-index: 2;
    }
    /*hover:item2*/
    #subject.state-4 .item2,
    #subject.state-3 .item2,
    #subject.state-2 .item2 {
      left: 20%;
    }
    /*hover:item3*/
    #subject.state-4 .item3,
    #subject.state-3 .item3 {
      left: 40%;
    }
    /*hover:item4*/
    #subject.state-4 .item4{
      left: 60%;
    }
    #subject.state-1 .item3,
    .item3 {
      background: mediumseagreen;
      left: 60%;
      z-index: 3;
    }
    #subject.state-3 .item4,
    #subject.state-2 .item4,
    #subject.state-1 .item4,
    .item4 {
      background: pink;
      left: 80%;
      z-index: 4;
    }
  </style>
</head>
<body>
<div id="subject" class="wrapper">
  <ul>
    <li class="item item1">1</li>
    <li class="item item2">2</li>
    <li class="item item3">3</li>
    <li class="item item4">4</li>
  </ul>
</div>
<script>
  $(function () {
    $('.item').hover(function () {
      if ($(this).hasClass('item1')) {
        $('#subject').removeClass().addClass('state-1');
      }
      if ($(this).hasClass('item2')) {
        $('#subject').removeClass().addClass('state-2');
      }
      if ($(this).hasClass('item3')) {
        $('#subject').removeClass().addClass('state-3');
      }
      if ($(this).hasClass('item4')) {
        $('#subject').removeClass().addClass('state-4');
      }
    });
    $('#subject').mouseleave(function () {
      $('#subject').removeClass();
    });
  });
</script>
</body>
</html>

以上是“JS如何模仿万科底部的新闻滑动特效”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!

推荐阅读:
  1. tab滑动特效
  2. banner滑动juqery特效 带自动切换

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

js

上一篇:vue项目中怎么实现支持多种语言

下一篇:vue中怎么实现表单双向绑定

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》