jQuery實(shí)現(xiàn)網(wǎng)站導(dǎo)航抖動(dòng)效果的代碼分享-創(chuàng)新互聯(lián)

今天小編給大家分享的是jQuery實(shí)現(xiàn)網(wǎng)站導(dǎo)航抖動(dòng)效果的代碼,相信很多人都不太了解,為了讓大家更加了解jQuery實(shí)現(xiàn)網(wǎng)站導(dǎo)航抖動(dòng)效果的代碼,所以給大家總結(jié)了以下內(nèi)容,一起往下看吧。一定會(huì)有所收獲的哦。

在宣威等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強(qiáng)發(fā)展的系統(tǒng)性、市場(chǎng)前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供成都網(wǎng)站設(shè)計(jì)、網(wǎng)站制作 網(wǎng)站設(shè)計(jì)制作按需定制開(kāi)發(fā),公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),品牌網(wǎng)站建設(shè),全網(wǎng)營(yíng)銷推廣,成都外貿(mào)網(wǎng)站建設(shè)公司,宣威網(wǎng)站建設(shè)費(fèi)用合理。

jQuery實(shí)現(xiàn)網(wǎng)站導(dǎo)航抖動(dòng)效果的代碼分享

使用jQuery實(shí)現(xiàn)網(wǎng)站導(dǎo)航抖動(dòng)效果

知識(shí)點(diǎn)

1、each遍歷節(jié)點(diǎn)

2、 animate()自定義動(dòng)畫

代碼

<!DOCTYPE html><html lang="en"><head>
    <meta charset="UTF-8">
    <title></title>
    <style>
        * {
            padding: 0;
            margin: 0;
            list-style: none;
        }
        .box {
            width: 350px;
            height: 350px;
            margin: 100px auto;
            cursor: pointer;
        }
        .box ul li {
            float: left;
            width: 80px;
            height: 80px;
            text-align: center;
            border: 1px solid #ccc;
            box-sizing: border-box;
            margin: 2px;
        }
        .box>ul>li>span {
            display: block;
            width: 24px;
            height: 24px;
            background: url("images/bg.png") 0 -24px no-repeat;
            margin: 10px auto;
        }
    </style></head><body>
    <p class="box">
        <ul>
            <li><span></span>百度</li>
            <li><span></span>淘寶</li>
            <li><span></span>新浪</li>
            <li><span></span>網(wǎng)易</li>
            <li><span></span>搜狐</li>
            <li><span></span>騰訊</li>
            <li><span></span>優(yōu)酷</li>
            <li><span></span>京東</li>
        </ul>
    </p><script type="text/javascript" src="lib/jquery-3.3.1.js"></script><script type="text/javascript">
    $(function () {
        // 1. 展示圖片
        var $li = $('.box>ul>li');
        $li.each(function (index, value) {
            $(this).children('span').css({
                'background': ' url("images/bg.png") 0 -' + index * 24 + 'px no-repeat'
            })
        });

        // 2. 抖動(dòng)動(dòng)畫
        $li.hover(function () {
            shake(this);
        }, function () {
            // 停止抖動(dòng)
            stopShake(this);
        });


        function shake(ele) {
            // 1. 設(shè)置css
            $(ele).css({
               'position': 'relative'
            });

            // 2. 確定走動(dòng)的值
            var animateLeft = $(ele).css('left') === '10px' ? '-10px' : '10px';
            $(ele).animate({
                left: animateLeft            }, 100, function () {
                shake(ele);
            });
        }

        function stopShake(ele) {
            $(ele).stop(true, false).css({
                left: '0'
            })
        }
    });</script></body></html>

運(yùn)行結(jié)果

鼠標(biāo)放上后會(huì)不停抖動(dòng)
jQuery實(shí)現(xiàn)網(wǎng)站導(dǎo)航抖動(dòng)效果的代碼分享jQuery實(shí)現(xiàn)網(wǎng)站導(dǎo)航抖動(dòng)效果的代碼分享

// 停止抖動(dòng)
            stopShake(this);
        });


        function shake(ele) {
            // 1. 設(shè)置css
            $(ele).css({
               'position': 'relative'
            });

            // 2. 確定走動(dòng)的值
            var animateLeft = $(ele).css('left') === '10px' ? '-10px' : '10px';
            $(ele).animate({
                left: animateLeft            }, 100, function () {
                shake(ele);
            });
        }

        function stopShake(ele) {
            $(ele).stop(true, false).css({
                left: '0'
            })
        }
    });</script></body></html>

運(yùn)行結(jié)果

鼠標(biāo)放上后會(huì)不停抖動(dòng)
jQuery實(shí)現(xiàn)網(wǎng)站導(dǎo)航抖動(dòng)效果的代碼分享jQuery實(shí)現(xiàn)網(wǎng)站導(dǎo)航抖動(dòng)效果的代碼分享

關(guān)于jQuery實(shí)現(xiàn)網(wǎng)站導(dǎo)航抖動(dòng)效果的代碼就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的參考價(jià)值,可以學(xué)以致用。如果喜歡本篇文章,不妨把它分享出去讓更多的人看到。

文章名稱:jQuery實(shí)現(xiàn)網(wǎng)站導(dǎo)航抖動(dòng)效果的代碼分享-創(chuàng)新互聯(lián)
文章路徑:http://www.muchs.cn/article6/dhosig.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供電子商務(wù)、網(wǎng)站制作、營(yíng)銷型網(wǎng)站建設(shè)、App開(kāi)發(fā)、軟件開(kāi)發(fā)、ChatGPT

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

成都網(wǎng)站建設(shè)