jQuery实现的滑块滑动导航效果示例


Posted in jQuery onJune 04, 2018

本文实例讲述了jQuery实现的滑块滑动导航效果。分享给大家供大家参考,具体如下:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>3water.com jquery滑动导航</title>
  <style>
    *{margin: 0;padding: 0;box-sizing: border-box;-moz-box-sizing: border-box;}
    body {
      font: 16px/20px 'Microsoft yahei,微软雅黑';
      color: #AFBBBB;
    }
    ul {
      list-style-type: none;
    }
    ul li {
      float: left;
    }
    a {
      text-decoration: none;
      color: #AFBBBB;
    }
    a:hover {
      color: #ffffff;
      cursor: pointer;
    }
    .clearfix:before,.clearfix:after {
      content:"";
      clear: both;
      display: table;
      height: 0;
      zoom: 1;
      overflow: hidden;
    }
    .nav {
      width:519px;
      margin: 0 auto;
    }
    .nav ul {
      background: gray;
      height: 35px;
      line-height: 35px;
      position: relative;
      padding: 0 5px;
    }
    .nav ul li {
      position: relative;
      padding: 0 25px;
    }
    .nav ul li>a {
      position: relative;
      z-index: 100; /*将a元素的z-index设置比li大,这样hover效果才不会无效*/
    }
    .nav ul li:last-child {
      width: 98px;
      height: 90%;
      position: absolute;
      z-index: 50;
      left: 5px;
      bottom: 0;
      top: 0;
      margin: auto;
      background: rgba(152,206,170,0.5);
      border-radius: 5px;
    }
  </style>
</head>
<body>
<div class="nav">
  <ul class="clearfix">
    <li><a href="javascript:void(0)" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >幼儿园</a></li>
    <li><a href="javascript:void(0)" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >小学</a></li>
    <li><a href="javascript:void(0)" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >初中</a></li>
    <li><a href="javascript:void(0)" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >高中</a></li>
    <li><a href="javascript:void(0)" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >大学</a></li>
    <li><a href="javascript:void(0)" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >社会</a></li>
    <li class="huadong" id="huaBlock"></li>
  </ul>
</div>
<script src="http://cdn.bootcss.com/jquery/2.1.0/jquery.js"></script>
<script>
  $(function(){
    $("ul li:not(:last)").hover(function(){
      $("#huaBlock").stop();  //停止正在运行的动画
      var curliWidth=$(this).outerWidth(),curleft=$(this).offset().left-$(this).parent().offset().left; //当前li的偏移量减去当前ul的偏移量就是li距离ul的距离
      // alert("curleft:"+curleft);
      $("#huaBlock").animate({"width":curliWidth,"left":curleft},500);
    },function(){
      $("#huaBlock").stop();
      $("#huaBlock").animate({"width":98,"left": 5},200);
    });
  });
</script>
</body>
</html>

使用在线HTML/CSS/JavaScript代码运行工具 http://tools.3water.com/code/HtmlJsRun测试运行效果如下:

jQuery实现的滑块滑动导航效果示例

希望本文所述对大家jQuery程序设计有所帮助。

jQuery 相关文章推荐
浅谈struts1 &amp; jquery form 文件异步上传
May 25 jQuery
jQuery简介_动力节点Java学院整理
Jul 04 jQuery
jQuery封装placeholder效果实现方法,让低版本浏览器支持该效果
Jul 08 jQuery
jQuery实现新闻播报滚动及淡入淡出效果示例
Mar 23 jQuery
jQuery实现的简单对话框拖动功能示例
Jun 05 jQuery
Angular5中调用第三方库及jQuery的添加的方法
Jun 07 jQuery
jQuery阻止事件冒泡实例分析
Jul 03 jQuery
jQuery实现仿京东防抖动菜单效果示例
Jul 06 jQuery
jQuery轻量级表单模型验证插件
Oct 15 jQuery
Vue CLI3.0中使用jQuery和Bootstrap的方法
Feb 28 jQuery
jquery+css实现Tab栏切换的代码实例
May 14 jQuery
jQuery实现雪花飘落效果
Aug 02 jQuery
jQuery实现常见的隐藏与展示列表效果示例
Jun 04 #jQuery
jQuery实现的简单获取索引功能示例
Jun 04 #jQuery
JS与jQuery实现ListBox上移,下移,左移,右移操作功能示例
May 31 #jQuery
jQuery基于Ajax实现读取XML数据功能示例
May 31 #jQuery
jQuery实现动态加载select下拉列表项功能示例
May 31 #jQuery
webpack里使用jquery.mCustomScrollbar插件的方法
May 30 #jQuery
jQuery 导航自动跟随滚动的实现代码
May 30 #jQuery
You might like
深入解析php模板技术原理【一】
2008/01/10 PHP
php 随机数的产生、页面跳转、件读写、文件重命名、switch语句
2009/08/07 PHP
处理php自动反斜杠的函数代码
2010/01/05 PHP
php中的观察者模式
2010/03/24 PHP
php图像处理函数大全(推荐收藏)
2013/07/11 PHP
ThinkPHP框架实现FTP图片上传功能示例
2019/04/08 PHP
Web版彷 Visual Studio 2003 颜色选择器
2007/01/09 Javascript
使用Firebug对js进行断点调试的图文方法
2011/04/02 Javascript
javascript中节点的最近的相关节点访问方法
2013/03/20 Javascript
ANT 压缩(去掉空格/注释)JS文件可提高js运行速度
2013/04/15 Javascript
JS实现仿京东淘宝竖排二级导航
2014/12/08 Javascript
jQuery通过扩展实现抖动效果的方法
2015/03/11 Javascript
jQuery循环遍历子节点并获取值的方法
2016/04/14 Javascript
基于JS代码实现简单易用的倒计时 x 天 x 时 x 分 x 秒效果
2017/07/13 Javascript
bootstrap paginator分页插件的两种使用方式实例详解
2017/11/14 Javascript
解决vuex数据页面刷新后初始化操作
2020/07/26 Javascript
[44:09]DOTA2上海特级锦标赛A组小组赛#1 EHOME VS MVP.Phx第二局
2016/02/25 DOTA
python数据清洗系列之字符串处理详解
2017/02/12 Python
win10下tensorflow和matplotlib安装教程
2018/09/19 Python
python将图片转base64,实现前端显示
2020/01/09 Python
python 安装库几种方法之cmd,anaconda,pycharm详解
2020/04/08 Python
keras的三种模型实现与区别说明
2020/07/03 Python
python matplotlib绘制三维图的示例
2020/09/24 Python
Python中的流程控制详解
2021/02/18 Python
python 制作本地应用搜索工具
2021/02/27 Python
详解移动端h5页面根据屏幕适配的四种方案
2020/04/15 HTML / CSS
amazeui页面校验功能的实现代码
2020/08/24 HTML / CSS
个人简历自我评价八例
2013/10/31 职场文书
中学生爱国演讲稿
2013/12/31 职场文书
煤矿安全知识竞赛活动总结
2014/07/07 职场文书
安全目标管理责任书
2014/07/25 职场文书
西柏坡导游词
2015/02/05 职场文书
行政上诉状范文
2015/05/23 职场文书
尊师重教主题班会
2015/08/14 职场文书
深入理解java.lang.String类的不可变性
2021/06/27 Java/Android
大型强子对撞机再次重启探索“第五种自然力”
2022/04/29 数码科技