手机版 | ------------全站资源有,统一解压码,解码平台,请点这里 ------------ 设首页 | 加收藏
当前位置: 网站首页 > jQuery库 > 文章 当前位置: jQ > 文章

jQuery菜单条鼠标跟随线条特效

时间:2020-06-30    点击: 次    来源:网络    作者:佚名 - 小 + 大

jQuery菜单条鼠标跟随线条特效
简要教程

这是一款简单的jQuery菜单条鼠标跟随线条特效。该特效在当鼠标在菜单项上移动时,会有线条跟随鼠标在菜单项下面移动,并且线条的长度会随着菜单项的长度而变化。

使用方法

在页面中引入jquery文件。

<script src="js/jquery.min.js" type="text/javascript"></script>                         
HTML结构

使用时,菜单的HTML结构如下:

<div class="menu">  <div class="menu-item current-menu-item">    <h6>Home</h6>    <div class="wee"></div>  </div>  <div class="menu-item">    <h6>Contact</h6>  </div>  <div class="menu-item">    <h6>About</h6>  </div>  <div class="menu-item">    <h6>Blog</h6>  </div>  <div class="menu-item">    <h6>Jobs</h6>  </div></div>                        
CSS样式

为菜单添加下面的CSS样式,你可以根据实际情况,添加自己的菜单样式。

.menu {  width: 100%;  display: flex;  align-items: center;  justify-content: center;}.menu .menu-item {  position: relative;  cursor: pointer;}.menu .menu-item .wee {  height: 2px;  width: 100%;  background-color: #002b75;  position: absolute;  left: 0;  bottom: 0;  transition: 0.75s;}.menu .menu-item h6 {  margin: 0;  padding: 0 1rem 1.5rem;  font-size: 1rem;  color: #232323;  transition: 0.75s;}.menu .menu-item:hover h6 { color: #002b75; }.menu .current-menu-item h6 { color: #002b75; }                                      
JavaScript

然后使用下面的jQuery代码来时线条在鼠标移动时,跟随鼠标移动。

$(document).ready(function() {  $(window).on('load resize', function() {    var $thisnav = $('.current-menu-item').offset().left;    $('.menu-item').hover(function() {      var $left = $(this).offset().left - $thisnav;      var $width = $(this).outerWidth();      var $start = 0;      $('.wee').css({ 'left': $left , 'width': $width });    }, function() {      var $initwidth = $('.current-menu-item').width();      $('.wee').css({ 'left': '0' , 'width': $initwidth });    });  });});                       

 jQuery菜单条鼠标跟随线条特效的原文地址为:https://codepen.io/cmdeveloped/pen/LdmMwE

 jQuery菜单条鼠标跟随线条特效 本地下载

上一篇:支持4种类型的jQuery轮播图插件EasySlides

下一篇:基于jQuery的移动端前端框架AKjs

浙ICP备18035339号-15  |   QQ:79720816  |  地址:蚂蚁分享-一个只做有用的分享。  |  13388629007  |  
Copyright © 2023 蚂蚁分享网 版权所有,授权www.tanan.net使用 Powered by ANTQQ.COM