溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

JQuery怎么實現電梯導航特效

發布時間:2022-02-23 09:12:25 來源:億速云 閱讀:184 作者:iii 欄目:開發技術

這篇“JQuery怎么實現電梯導航特效”文章的知識點大部分人都不太理解,所以小編給大家總結了以下內容,內容詳細,步驟清晰,具有一定的借鑒價值,希望大家閱讀完這篇文章能有所收獲,下面我們一起來看看這篇“JQuery怎么實現電梯導航特效”文章吧。

效果如下: 

JQuery怎么實現電梯導航特效

以下是代碼實現:

<!DOCTYPE html>
<html lang="en">
 
<head>
    <meta charset="utf-8" />
    <title>基于JQuery實現電梯導航特效</title>
    <style type="text/css">
        * {
            margin: 0;
            padding: 0;
            font-family: 'microsoft yahei';
        }
 
        #loutinav {
            width: 35px;
            position: fixed;
            top: 100px;
            left: 50px;
            border: 1px solid #ddd;
            display: none;
 
        }
 
        #loutinav ul li {
            width: 35px;
            height: 32px;
            border-bottom: 1px dotted #DDDDDD;
            list-style: none;
            font-size: 12px;
            text-align: center;
            position: relative;
            cursor: pointer;
            padding: 10px 0;
            background: #918888;
            color: #fff;
        }
 
        #loutinav ul li span {
            width: 35px;
            height: 32px;
            padding: 10px 0;
            position: absolute;
            top: 0;
            left: 0;
        }
 
        #loutinav ul li.last {
            background: #5e4a4a;
            color: #fff;
            border-bottom: 1px solid #ddd;
        }
 
        #loutinav ul li.active span {
            background: #c00;
            color: #fff;
            display: block;
        }
 
        #loutinav ul li:hover span {
            background: #c00;
            color: #fff;
            display: block;
        }
 
        #header {
            width: 1000px;
            height: 1000px;
            background: #cc6633;
            margin: 0 auto;
            font-size: 50px;
            line-height: 1000px;
            text-align: center;
            color: #000;
        }
 
        #main {
            width: 1000px;
            background: #66ff66;
            margin: 0 auto;
        }
 
        #main .louti {
            height: 600px;
            width: 1000px;
            font-size: 50px;
            color: #fff;
            font-weight: bold;
            text-align: center;
            line-height: 600px;
        }
 
        #footer {
            width: 1000px;
            height: 400px;
            background: red;
            margin: 0 auto;
            font-size: 50px;
            line-height: 400px;
            text-align: center;
            color: #000;
        }
    </style>
</head>
 
<body>
    <div id="loutinav">
        <ul>
            <li class="active">
                <span>享品質</span>
            </li>
            <li>
                <span>服飾美妝</span>
            </li>
            <li>
                <span>電腦數碼</span>
            </li>
            <li>
                <span>3C運動</span>
            </li>
            <li>
                <span>愛吃</span>
            </li>
            <li>
                <span>母嬰居家</span>
            </li>
            <li>
                <span>圖書汽車</span>
            </li>
            <li>
                <span>虛擬</span>
            </li>
            <li>
                <span>還沒逛夠</span>
            </li>
            <li class="last">頂部</li>
        </ul>
    </div>
    <div id="header">
        向下滾動鼠標查看效果
    </div>
    <div id="main">
        <div class="louti" >
            享品質
        </div>
        <div class="louti" >
            服飾美妝
        </div>
        <div class="louti" >
            電腦數碼
        </div>
        <div class="louti" >
            3C運動
        </div>
        <div class="louti" >
            愛吃
        </div>
        <div class="louti" >
            母嬰居家
        </div>
        <div class="louti" >
            圖書汽車
        </div>
        <div class="louti" >
            虛擬
        </div>
        <div class="louti" >
            還沒逛夠
        </div>
    </div>
    <div id="footer">
        網站底部
    </div>
    <script src="js/jquery-1.8.3.min.js"></script>
    <script>
        $(function () {
            $(window).on('scroll', function () {
                var $scroll = $(this).scrollTop();
                // 顯示樓層標簽
                if ($scroll >= 800) {
                    $('#loutinav').show();
                } else {
                    $('#loutinav').hide();
                }
 
                // 拖動滾輪,點亮對應的樓層標簽
                $('.louti').each(function () {
                    var $loutitop = $('.louti').eq($(this).index()).offset().top + 400;
                    // 樓層的top大于滾動條的距離
                    if ($loutitop > $scroll) {
                        $('#loutinav li').removeClass('active');
                        $('#loutinav li').eq($(this).index()).addClass('active');
                        // 中斷循環
                        return false;
                    }
                });
            });
 
            // 獲取每個樓梯的offset().top,點擊樓層讓對應的內容模塊移動到對應的位置  
            var $loutili = $('#loutinav li').not('.last');
            $loutili.on('click', function () {
                $(this).addClass('active').siblings('li').removeClass('active');
                var $loutitop = $('.louti').eq($(this).index()).offset().top;
                // 獲取每個樓梯的offsetTop值
                // $('html,body')兼容問題body屬于chrome
                $('html,body').animate({
                    scrollTop: $loutitop
                })
            });
 
            // 回到頂部
            $('.last').on('click', function () {
                // $('html,body')兼容問題body屬于chrome
                $('html,body').animate({
                    scrollTop: 0
                })
            });
 
        })
    </script>
</body>
 
</html>

以上就是關于“JQuery怎么實現電梯導航特效”這篇文章的內容,相信大家都有了一定的了解,希望小編分享的內容對大家有幫助,若想了解更多相關的知識內容,請關注億速云行業資訊頻道。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女