博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
html5中的锚点特效
阅读量:6275 次
发布时间:2019-06-22

本文共 3990 字,大约阅读时间需要 13 分钟。

hot3.png

html5的强大让我感觉越发兴奋,今天在写一个js demo---网页定位导航特效的时候,在涉及到页面的快速定位的时候,我还以为要用很复杂的js实现,结果之后才发现,html5有一个很酷的效果,虽然这个锚点特效只能支持Chrome,火狐,IE8以上等浏览器。但是在不考虑一些旧的浏览器的兼容情况的时候,可以使用,而且效果是杠杠的

在html5中,锚点使用id名称而不再是name属性了

demo 例子:

<!DOCTYPE html>

    <html>
        <head>
            <meta charset="utf-8"/>
            <title>山寨版购物网--实现网页定位导航系统</title>
            <style>
               body{margin: 0;padding: 0;}
               h1{margin-left: 20px;}
               .content{ width:1063px;margin: 0 auto;height: 5000px;}
               ul{list-style: none;}
               .item{width:826px;margin: 0 auto;height: 1000px;margin-bottom: 30px;border:1px dotted #0088bb;}
               .item li{width:250px;height: 300px;float: left;display: inline;margin-right: 10px;border:1px solid #0088bb;}
               .item h2{font-size: 16px;margin-bottom: 10px;clear: both;}
               img{width:250px;height: 300px;}
               #menu{ position: fixed;top:100px;left: 50%;margin-left: 380px;width: 80px;}
               #menu li a{ display: block;margin: 5px 0;font-size: 14px;font-weight: bold;color: #333;width: 80px;height: 50px;line-height: 50px;text-decoration: none;text-align: center;}
               #menu ul li a:hover,
               #menu ul li a .current{
                  color: #fff; background: #0088bb;
               }
            </style>
        </head>
        <body>
            <div id="menu">
                <ul>
                    <li><a href="#item1">1F 洗浴</a></li>
                    <li><a href="#item2">2F 美妆</a></li>
                    <li><a href="#item3">3F 童装</a></li>
                    <li><a href="#item4">4F 书籍</a></li>
                    <li><a href="#item5">5F 数码</a></li>
                </ul>
            </div>
            <div class="content">
                <h1>购物网</h1>
                <div id="item1" class="item">
                    <h2>1F 洗浴</h2>
                    <ul>
                        <li><a href=""><img src="1.jpg" alt=""/></a></li>
                        <li><a href=""><img src="1.jpg" alt=""/></a></li>
                        <li><a href=""><img src="1.jpg" alt=""/></a></li>
                        <li><a href=""><img src="1.jpg" alt=""/></a></li>
                        <li><a href=""><img src="1.jpg" alt=""/></a></li>
                        <li><a href=""><img src="1.jpg" alt=""/></a></li>
                        <li><a href=""><img src="1.jpg" alt=""/></a></li>
                        <li><a href=""><img src="1.jpg" alt=""/></a></li>
                        <li><a href=""><img src="1.jpg" alt=""/></a></li>
                    </ul>
                </div>
                
                <div id="item2" class="item">
                    <h2>2F 美妆</h2>
                    <ul>
                        <li><a href=""><img src="2.jpg" alt=""/></a></li>
                        <li><a href=""><img src="2.jpg" alt=""/></a></li>
                        <li><a href=""><img src="2.jpg" alt=""/></a></li>
                        <li><a href=""><img src="2.jpg" alt=""/></a></li>
                        <li><a href=""><img src="2.jpg" alt=""/></a></li>
                        <li><a href=""><img src="2.jpg" alt=""/></a></li>
                        <li><a href=""><img src="2.jpg" alt=""/></a></li>
                        <li><a href=""><img src="2.jpg" alt=""/></a></li>
                        <li><a href=""><img src="2.jpg" alt=""/></a></li>
                    </ul>
                </div>
                
                <div id="item3" class="item">
                    <h2>3F 童装</h2>
                    <ul>
                        <li><a href=""><img src="3.jpg" alt=""/></a></li>
                        <li><a href=""><img src="3.jpg" alt=""/></a></li>
                        <li><a href=""><img src="3.jpg" alt=""/></a></li>
                        <li><a href=""><img src="3.jpg" alt=""/></a></li>
                        <li><a href=""><img src="3.jpg" alt=""/></a></li>
                        <li><a href=""><img src="3.jpg" alt=""/></a></li>
                        <li><a href=""><img src="3.jpg" alt=""/></a></li>
                        <li><a href=""><img src="3.jpg" alt=""/></a></li>
                        <li><a href=""><img src="3.jpg" alt=""/></a></li>
                    </ul>
                </div>
                
                <div id="item4" class="item">
                    <h2>4F 书籍</h2>
                    <ul>
                        <li><a href=""><img src="4.jpg" alt=""/></a></li>
                        <li><a href=""><img src="4.jpg" alt=""/></a></li>
                        <li><a href=""><img src="4.jpg" alt=""/></a></li>
                        <li><a href=""><img src="4.jpg" alt=""/></a></li>
                        <li><a href=""><img src="4.jpg" alt=""/></a></li>
                        <li><a href=""><img src="4.jpg" alt=""/></a></li>
                        <li><a href=""><img src="4.jpg" alt=""/></a></li>
                        <li><a href=""><img src="4.jpg" alt=""/></a></li>
                        <li><a href=""><img src="4.jpg" alt=""/></a></li>
                    </ul>
                </div>
                
                <div id="item5" class="item">
                    <h2>5F 数码</h2>
                    <ul>
                        <li><a href=""><img src="5.jpg" alt=""/></a></li>
                        <li><a href=""><img src="5.jpg" alt=""/></a></li>
                        <li><a href=""><img src="5.jpg" alt=""/></a></li>
                        <li><a href=""><img src="5.jpg" alt=""/></a></li>
                        <li><a href=""><img src="5.jpg" alt=""/></a></li>
                        <li><a href=""><img src="5.jpg" alt=""/></a></li>
                        <li><a href=""><img src="5.jpg" alt=""/></a></li>
                        <li><a href=""><img src="5.jpg" alt=""/></a></li>
                        <li><a href=""><img src="5.jpg" alt=""/></a></li>
                    </ul>
                </div>
                
            </div>
        </body>
    </html>

  html5的功能还是很强大的,希望各浏览器能早日统一

转载于:https://my.oschina.net/sunshinewyf/blog/487293

你可能感兴趣的文章
SAP S/4HANA Cloud: Revolutionizing the Next Generation of Cloud ERP
查看>>
《分歧者3》观后感
查看>>
GIS基础软件及操作(九)
查看>>
10天学安卓-第一天
查看>>
view和activity的区别(转)
查看>>
MySQL的create table as 与 like区别(转)
查看>>
SQLserver 存储过程执行错误记录到表
查看>>
Spring Boot 之 RESRful API 权限控制
查看>>
Redis——常用命令操作
查看>>
UDP 单播、广播和多播
查看>>
windows linux—unix 跨平台通信集成控制系统----系统硬件信息获取
查看>>
ThinkPad E550 安装 WIN7 的启动 U 盘制作
查看>>
在 Windows 下远程桌面连接 Linux - XManager 篇
查看>>
tomcat如何路由映射网址
查看>>
如何开始容器化
查看>>
为什么POLARDB是云计算2.0时代产品进化的关键里程碑?
查看>>
HTTP 协议解析
查看>>
十面埋伏? 程序世界里的不信任原则
查看>>
Use our script to build OGRE, CEGUI, FreeImage, Cg and OIS from CVS
查看>>
姚期智:算法将推动下一波AI浪潮,现有革新将达极限
查看>>