網站首頁 編程語言 正文
本文實例為大家分享了jquery實現樓層滾動的具體代碼,供大家參考,具體內容如下
效果圖
html
<div id="floorNav">
? ? <ul>
? ? ? <li>1F<span>服飾</span></li>
? ? ? <li>2F<span>美妝</span></li>
? ? ? <li>3F<span>手機</span></li>
? ? ? <li>4F<span>家電</span></li>
? ? ? <li>5F<span>數碼</span></li>
? ? ? <li>6F<span>運動</span></li>
? ? ? <li>7F<span>居家</span></li>
? ? ? <li>8F<span>母嬰</span></li>
? ? ? <li>9F<span>食品</span></li>
? ? ? <li>10F<span>圖書</span></li>
? ? ? <li>11F<span>服務</span></li>
? ? </ul>
? </div>
? <div id="header"></div>
? <div id="content">
? ? <ul>
? ? ? <li style="background: #8b0000;">服飾</li>
? ? ? <li style="background: #123;">美妝</li>
? ? ? <li style="background: #667;">手機</li>
? ? ? <li style="background: #558;">家電</li>
? ? ? <li style="background: #900;">數碼</li>
? ? ? <li style="background: #456;">運動</li>
? ? ? <li style="background: #789;">居家</li>
? ? ? <li style="background: #234;">母嬰</li>
? ? ? <li style="background: #567;">食品</li>
? ? ? <li style="background: #887;">圖書</li>
? ? ? <li style="background: #980;">服務</li>
? ? </ul>
</div>
css
<style type="text/css">
? ? body,
? ? ul,
? ? li {
? ? ? padding: 0;
? ? ? margin: 0;
? ? }
? ? li {
? ? ? list-style: none;
? ? }
? ? #floorNav {
? ? ? display: none;
? ? ? position: fixed;
? ? ? top: 100px;
? ? ? left: 50px;
? ? ? width: 32px;
? ? ? border: 1px solid #cecece;
? ? }
? ? #floorNav li {
? ? ? position: relative;
? ? ? width: 32px;
? ? ? height: 32px;
? ? ? border-bottom: 1px solid #cecece;
? ? ? text-align: center;
? ? ? line-height: 32px;
? ? ? font-size: 12px;
? ? }
? ? #floorNav span {
? ? ? display: none;
? ? ? position: absolute;
? ? ? top: 0;
? ? ? left: 0;
? ? ? width: 32px;
? ? ? height: 32px;
? ? ? background: red;
? ? ? color: white;
? ? }
? ? #floorNav li:hover span,
? ? #floorNav li.hover span {
? ? ? display: block;
? ? ? cursor: default;
? ? }
? ? #floorNav li:last-child {
? ? ? border-bottom: none;
? ? }
? ? #header,
? ? #footer {
? ? ? width: 1000px;
? ? ? height: 1000px;
? ? ? background: darkgoldenrod;
? ? ? margin: 0 auto;
? ? }
? ? #content li {
? ? ? width: 1000px;
? ? ? height: 600px;
? ? ? margin: 0 auto;
? ? ? font-size: 40px;
? ? ? text-align: center;
? ? ? line-height: 600px;
? ? }
</style>
js
<script src="js/jquery-1.11.0.js" type="text/javascript" charset="utf-8"></script>
? <script type="text/javascript">
? ? $(function () {
? ? ? var flag = true;
? ? ? $(window).scroll(function () {
? ? ? ? if (flag) {
? ? ? ? ? var t = $(this).scrollTop();
? ? ? ? ? if (t > 500) {
? ? ? ? ? ? $("#floorNav").fadeIn();
? ? ? ? ? } else {
? ? ? ? ? ? $("#floorNav").fadeOut();
? ? ? ? ? }
? ? ? ? ? $("#content li").each(function () {
? ? ? ? ? ? if (t >= $(this).offset().top - $(this).outerHeight() / 2) {
? ? ? ? ? ? ? var index = $(this).index();
? ? ? ? ? ? ? $("#floorNav li")
? ? ? ? ? ? ? ? .eq(index)
? ? ? ? ? ? ? ? .addClass("hover")
? ? ? ? ? ? ? ? .siblings()
? ? ? ? ? ? ? ? .removeClass("hover");
? ? ? ? ? ? }
? ? ? ? ? });
? ? ? ? }
? ? ? });
? ? ? $("#floorNav li").click(function () {
? ? ? ? flag = false;
? ? ? ? var index = $(this).index();
? ? ? ? $("html,body").animate(
? ? ? ? ? {
? ? ? ? ? ? scrollTop: $("#content li").eq(index).offset().top,
? ? ? ? ? },
? ? ? ? ? () => {
? ? ? ? ? ? flag = true;
? ? ? ? ? }
? ? ? ? );
? ? ? ? $(this).addClass("hover").siblings().removeClass("hover");
? ? ? });
? ? });
</script>
原文鏈接:https://blog.csdn.net/WU567_/article/details/107051969
相關推薦
- 2022-06-11 C#把EXCEL數據轉換成DataTable_C#教程
- 2022-09-08 Python?避免字典和元組的多重嵌套問題_python
- 2022-10-29 Centos8系統配置Redis實現開機自啟
- 2022-09-27 linux?shell中Grep命令查找多個字符串(grep同時匹配多個關鍵字或任意關鍵字)_lin
- 2022-06-22 Android實現歡迎滑動頁面_Android
- 2022-09-28 Python使用captcha制作驗證碼的實現示例_python
- 2022-10-11 app:transformClassesAndResourcesWithProguardForRel
- 2022-10-15 C++回調函數實現計算器和qsort_C 語言
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支