导航菜单底部滑动条跟随效果_html/css_WEB-ITnose

php中文网
发布: 2016-06-21 08:57:53
原创
1720人浏览过

网上昨天学了一个导航条效果  今天手动实现了一下  开心。。。

翠花,上效果图!

表单大师AI
表单大师AI

一款基于自然语言处理技术的智能在线表单创建工具,可以帮助用户快速、高效地生成各类专业表单。

表单大师AI 74
查看详情 表单大师AI

实现代码如下(思路见代码):

<!DOCTYPE html><html><head>    <meta name="viewport" content="width=device-width" />    <title>navdemo1</title>    <style>        /*           1.位置属性(position, top, right, z-index, display, float等)            2.大小(width, height, padding, margin)            3.文字系列(font, line-height, letter-spacing, color- text-align等)            4.背景(background, border等)           5.其他(animation, transition等)             */        * {            padding: 0;            margin: 0;            font-family: 'Microsoft YaHei';        }        a{text-decoration:none;}        li{list-style:none;}        .nav-wrap{position:relative;background-color:#000;}        .nav-wrap .nav{width:1000px;margin:0 auto; overflow:hidden;}        .nav-wrap .nav li{float:left;}        .nav-wrap .nav li a{display:block; height:50px;padding:0 50px;line-height:50px;color:#fff;transition:background-color 0.3s linear;}        .nav-wrap .nav li a:hover,.nav-wrap .nav li a.active{background-color:#484646;}        .nav-wrap .line{display:block;position:absolute;bottom:0;width:50px;height:2px;background-color:#ff6a00;}    </style>    <script src="~/Scripts/jquery-1.8.2.js"></script>    <script src="~/Scripts/jquery.easing.1.3.js"></script>    <script>        $(function () {            navdeal();        });        //导航条效果处理        //思路:        //1.下滑条绝对定位到导航条模块的底部         //2.js控制下滑条 宽度=当前菜单项的宽度  左边距=当前菜单项相对父元素(.nav-wrap)的左偏移         //3.加上easing.js中的弹性效果        var navdeal = function () {            var $item_active = $('.nav-wrap .nav li a.active');            var $nav_line = $('.nav-wrap .line');            var item_width = $item_active.outerWidth();            var item_position_left = $item_active.position().left;            $nav_line.css({ 'width': item_width, 'margin-left': item_position_left });                        //菜单项鼠标移入,移出事件绑定            $('.nav-wrap .nav li a').bind({                mouseover: function () {                    var item_width = $(this).outerWidth();                    var item_position_left = $(this).position().left;                    $nav_line.stop().animate({ 'width': item_width, 'margin-left': item_position_left }, 800, 'easeOutBounce');                },                mouseout: function () {                    $nav_line.stop().animate({ 'width': item_width, 'margin-left': item_position_left }, 800, 'easeOutBounce');                }            });        }    </script></head><body>    <div class="nav-wrap">        <ul class="nav">            <li><a href="#" class="active">首页</a></li>            <li><a href="#">我的订单</a></li>            <li><a href="#">我的购物车</a></li>            <li><a href="#">退出</a></li>        </ul>        <span class="line"></span>    </div></body></html>
登录后复制
HTML速学教程(入门课程)
HTML速学教程(入门课程)

HTML怎么学习?HTML怎么入门?HTML在哪学?HTML怎么学才快?不用担心,这里为大家提供了HTML速学教程(入门课程),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号