js css3鼠标悬停文字导航菜单下划线效果



318 1268 423



特效描述:js css3 鼠标悬停 文字导航菜单 下划线效果,js css3悬停文字下划线效果

代码结构

1. HTML代码

<h1>鼠标悬停动画事件</h1>
<nav class="mynav">
  <ul>
    <li><a href="">Home</a></li>
    <li><a href="">About</a></li>
    <li><a href="">Company</a></li>
    <li><a href="">Work</a></li>
    <li><a href="">Clients</a></li>
    <li><a href="">Contact</a></li>
  </ul>
</nav>
<span class="target"></span>
<script>
"use strict";
(function () {
  var target = document.querySelector(".target");
  var links = document.querySelectorAll(".mynav a");
  var colors = ["deepskyblue", "orange", "firebrick", "gold", "magenta", "black", "darkblue"];
  function mouseenterFunc() {
    if (!this.parentNode.classList.contains("active")) {
      for (var i = 0; i < links.length; i++) {
        if (links[i].parentNode.classList.contains("active")) {
          links[i].parentNode.classList.remove("active");
        }
        links[i].style.opacity = "0.25";
      }
      this.parentNode.classList.add("active");
      this.style.opacity = "1";
      var width = this.getBoundingClientRect().width;
      var height = this.getBoundingClientRect().height;
      var left = this.getBoundingClientRect().left + window.pageXOffset;
      var top = this.getBoundingClientRect().top + window.pageYOffset;
      var color = colors[Math.floor(Math.random() * colors.length)];
      target.style.width = width + "px";
      target.style.height = height + "px";
      target.style.left = left + "px";
      target.style.top = top + "px";
      target.style.borderColor = color;
      target.style.transform = "none";
    }
  }
  for (var i = 0; i < links.length; i++) {
    links[i].addEventListener("click", function (e) {
      return e.preventDefault();
    });
    links[i].addEventListener("mouseenter", mouseenterFunc);
  }
  function resizeFunc() {
    var active = document.querySelector(".mynav li.active");
    if (active) {
      var left = active.getBoundingClientRect().left + window.pageXOffset;
      var top = active.getBoundingClientRect().top + window.pageYOffset;
      target.style.left = left + "px";
      target.style.top = top + "px";
    }
  }
  window.addEventListener("resize", resizeFunc);
})();</script>



用户评论
大牛,别默默的看了,快登录帮我点评一下吧!:)      登录 | 注册


热门标签: flash导航菜单 flash导航条 flash导航 flash菜单 flash下拉菜单 flash下拉导航菜单 导航切换 菜单切换 右键菜单 滑动导航菜单 滑动导航 滑动菜单 滚动导航菜单 滚动菜单 滚动导航 收缩菜单 收缩导航 h5动画导航 h5动画菜单 html5动画导航 html5动画菜单 浮动菜单 浮动导航 滚动切换 滚动条切换 滑动选项卡 滑动切换 滑动手风琴 选项卡切换 选项卡 切换 tab切换 页面切换 选项卡插件 切换插件 滑动星星打分 导航菜单 导航条 菜单栏 导航栏 分类导航 响应式导航条 响应式导航 其他 文字切换 文字选项卡 固定导航 固定菜单 导航菜单插件 导航插件 菜单插件 鼠标滑过 鼠标悬停 跟随鼠标移动

×
×

注册

官方QQ群

扫描上面二维码加微信群

官方QQ群

jQuery/js讨论群
群号:642649996
Css3+Html5讨论群
群号:322131262

加群请备注:从官网了解到