主頁 > 企業開發 > 實際開發常用的jquey事件型別,并運用到圖片相冊

實際開發常用的jquey事件型別,并運用到圖片相冊

2020-09-12 05:36:56 企業開發

滑鼠事件

.click  滑鼠單擊

.dblclick  滑鼠雙擊

    // 單擊事件
    $("a").click(function(){
        $("img").eq($(this).index()) // 獲取當前點擊的a的index
                .css({"opacity":"1"})
                .siblings()
                .css({"opacity":"0"});
    });

    // 雙擊事件
    $("a").dblclick(function(){
        $("img").eq($(this).index()) // 獲取當前點擊的a的index
                .css({"opacity":"1"})
                .siblings()
                .css({"opacity":"0"});
    });

.mousedown()  滑鼠按下

.mouseup()  滑鼠松開

.mousedown+.mouseup=click

知識點補充:mousedown和mouseup事件滑鼠左鍵點擊和滑鼠右鍵點擊都是可以實作的,click和dblclick事件只有滑鼠左鍵點擊才能實作

    // 滑鼠按下
    $("a").mousedown(function(){
        console.log("滑鼠按下");
    });

    // 滑鼠松開
    $("a").mouseup(function(){
        console.log("滑鼠松開");
    });

.mouseenter() 滑鼠進入

.mouseleave()  滑鼠移出

有點類似于hover的感覺

    // 滑鼠移入
    $("a").mouseenter(function(){
        console.log("滑鼠移入");
    });

    // 滑鼠移出
    $("a").mouseleave(function(){
        console.log("滑鼠移出");
    });

mouseenter+mouseleave=hover

.hover() 里面可以放兩個函式,第一個函式為移入的狀態,第二個函式為移出的狀態,多用于移出時還原

    // 滑鼠懸停
    $("a").hover(function(){
        $("img").eq($(this).index()) // 獲取當前點擊的a的index
                .css({"opacity":"1"})
                .siblings()
                .css({"opacity":"0"});
    });

    // 滑鼠懸停(over和out)
    $("a").hover(function(){
        $("img").eq($(this).index()) 
                .css({"opacity":"1"})
                .siblings()
                .css({"opacity":"0"});
    },function(){
        $("img").eq($(this).index()) 
                .css({"opacity":"0"})
                .siblings()
                .css({"opacity":"1"});
    });

mouseover 滑鼠進入(包括子元素)

mouseout 滑鼠移出(包括子元素)

比較少用,因為有冒泡和捕獲

    // 滑鼠進入元素及其子元素
    $("a").mouseover(function(){
        $("img").eq($(this).index()) 
                .css({"opacity":"1"})
                .siblings()
                .css({"opacity":"0"});
    });
    // 滑鼠離開元素及其子元素
    $("a").mouseout(function(){
        $("img").eq($(this).index()) 
                .css({"opacity":"1"})
                .siblings()
                .css({"opacity":"0"});
    });

mousemove 在元素內部移動

一有移動就會觸發,因此非常消耗資源

    // 滑鼠移動
    $("a").mousemove(function(){
        console.log("滑鼠移動");
    });

scroll 滑鼠拖拽滾動條

滑鼠一滾動就會觸發,因此消耗資源

    // 滑鼠滾動
    $("a").scroll(function(){
        console.log("滑鼠滾動");
    });

 

鍵盤事件

keydown  當鍵盤或者按鍵被按下時

引數為event,是鍵盤事件的屬性

event.key 按下的鍵

event.keyCode  按下的鍵的鍵碼(常用于識別左右上下箭頭)

    // 鍵盤按下
    $(document).keydown(function(event){
        console.log(event);
        console.log(event.key);//a
        console.log(event.keyCode);//65
    });

滑鼠不等于游標焦點

keydown只能在聚焦中有用

window 代表瀏覽器的視窗,document 是 HTML 檔案的根節點

從常理上說,元素沒有焦點是不能觸發鍵盤事件的(除了window、document等,可以理解為只要在這個頁面上,他們都是聚焦的),

觸發鍵盤事件常用的就是表單元素


 

keyup 按鍵被釋放的時候,發生在當前獲得焦點的元素上

keydown 鍵盤被按下即可(包括所有鍵,以及輸入法輸入的內容)

keypress 鍵盤按鍵被按下的時候(必須是按下字符鍵,不包括其他按鍵,也不包括輸入法輸入的文字)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script src="jquery.js"></script>
    <script>
        $(function(){
            $("input").keydown(function(e){
                console.log("keydown");
            });
        })
        $(function(){
            $("input").keypress(function(e){
                console.log("keypress");
            });
        })

    </script>
</head>
<body>

<form>
    <input type="text">
</form>

</body>
</html>

 

 

 在input框中輸入內容的時候同樣顯示在下面的p標簽中

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script src="jquery.js"></script>
    <script>
        $(function(){
            $("input").keydown(function(e){
                var text=$(this).val();
                $("p").text(text);
            });
        })

    </script>
</head>
<body>

<form>
    <input type="text">
</form>
<p></p>
</body>
</html>

 

 

 

其他事件

.ready()  DOM加載完成

$(document).ready(function())


 

.resize() 調整瀏覽器視窗大小,只針對window物件

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script src="jquery.js"></script>
    <script>
        $(function(){
            $(document).resize(function(){
                console.log("document+resize");
            });
            $(window).resize(function(){
                console.log("window+resize");
            });
        })

    </script>
</head>
<body>

<form>
    <input type="text">
</form>
<p></p>
</body>
</html>

 

 

 .focus()  獲取焦點

.blur()  失去焦點

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script src="jquery.js"></script>
    <script>
        $(function(){
            $("input").focus(function(){
                console.log("(*^▽^*)");
            });
            $("input").blur(function(){
                console.log("o(╥﹏╥)o");
            });
        })

    </script>
</head>
<body>

<form>
    <input type="text">
</form>
<p></p>
</body>
</html>

 

 

 .change() 元素的值發生改變,常用于input

有延遲機制,當快速改變內容時,不是實時跟著觸發事件

在輸入框中輸入的程序中,不會觸發.change事件,當游標離開或者手動點擊時才會觸發

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script src="jquery.js"></script>
    <script>
        $(function(){
            $("input").change(function(){
                console.log("change");
            });
        })

    </script>
</head>
<body>

<form>
    <input type="number">
</form>
<p></p>
</body>
</html>

或者select串列的選擇也會觸發

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script src="jquery.js"></script>
    <script>
        $(function(){
            $("select").change(function(){
                console.log("change");
            });
        })

    </script>
</head>
<body>

<form>
    <select name="" id="">
        <option value="">1</option>
        <option value="">2</option>
        <option value="">3</option>
    </select>
</form>
<p></p>
</body>
</html>

 

 

 

.select() 當input或者textarea中的文本被選中時觸發,針對于可選中文字的輸入框

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script src="jquery.js"></script>
    <script>
        $(function(){
            $("input").select(function(){
                console.log("select");
            });
        })

    </script>
</head>
<body>

<form>
    <input type="text" value="這是文本哦">
</form>
<p></p>
</body>
</html>

 

 

 

.submit() 表單提交事件

button是html新增標簽,在其他地方依然是普通按鈕,但是在非IE瀏覽器中,在表單內部會起到提交表單的功能

用處:

1、提交表單

2、禁止提交表單(回呼函式回傳值為false)

3、提交表單時進行指定操作(表單驗證)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script src="jquery.js"></script>
    <script>
        $(function(){
            // 給input[type="button"]添加提交表單的功能
            $("input[type='button']").click(function(){
                $("form").submit();//提交表單
            });
            //阻止表單提交
            $("button").click(function(){
                $("form").submit(function(){
                    return false;//只要回呼函式的回傳值是假,表單就不會被提交
                });
            });
            //表單驗證
            $("form").submit(function(){
                if($("input[type='text']").val()!="cyy") return false;
            })
        })

    </script>
</head>
<body>

<form action="javascript:alert('我被提交啦~')">
    <input type="text">
    <input type="button" value="button按鈕"><!-- 不能提交表單 -->
    <button>提交按鈕</button><!-- 可以提交表單 -->
</form>
<p></p>
</body>
</html>

 

 

 

事件引數 event

event.keyCode  左37 右39 上38 下 40

滑鼠在div框移動時,獲取滑鼠在頁面中的位置

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script src="jquery.js"></script>
    <script>
        $(function(){
            $("div").mousemove(function(event){
                $(".span1").text(event.pageX);
                $(".span2").text(event.pageY);
            })
        })

    </script>
    <style>
    div{
        width:300px;
        height:300px;
        border:1px solid;
        margin:0 auto;
        text-align: center;
        line-height:300px;
        color:orange;
    }
    </style>
</head>
<body>

<div>
    pageX:<span class="span1"></span>
    pageY:<span class="span2"></span>
</div>

</body>
</html>

 

 

 

事件系結與取消

.on(事件,[選擇器],[值],函式) 系結一個或多個事件

以下兩種方式效果相同

    // 單擊事件
    $("a").click(function(){
        index=$(this).index(); // 獲取當前點擊的a的index
        swiper();
    });

    //改寫成on的系結
    $(document).on("click","a",function(event){
        event.stopPropagation();//阻止冒泡
        index=$(this).index(); // 獲取當前點擊的a的index
        swiper();
    });

為什么使用on方法:

如果是動態生成的元素,使用.click這種方式是無法系結的,因為會找不到該元素

需要使用live方法

從jquery1.7開始,把 bind  delegate  live 方法給移除,使用了 on 方法

這種方式可以獲取到動態生成的元素,因為是從document開始搜索的

    $(document).on("click","a",function(event){
        event.stopPropagation();//阻止冒泡
        index=$(this).index(); // 獲取當前點擊的a的index
        swiper();
    });

 

也可用于系結多個事件

    //系結多個事件
    $("a").add(document).on({
        click:function(event){
            event.stopPropagation();//阻止冒泡
            index=$(this).index(); // 獲取當前點擊的a的index
            swiper();
        },
        mouseenter:function(event){
            event.stopPropagation();//阻止冒泡
            index=$(this).index(); // 獲取當前點擊的a的index
            swiper();
        },
        keydown:function(event){
            if(event.keyCode==37){//
                index=index>0 ? --index : $("a").length-1;
            }else if(event.keyCode==39){//
                index=index<$("a").length-1 ? ++index : 0;
            }else{
                return true;
            }
            swiper();
        }
    });

.off() 取消事件系結

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script src="jquery.js"></script>
    <script>
        $(function(){
            $(".bind").on("click",function(){
                $(".btn").on("click",flash)
                         .text("點擊有效");
            });
            $(".unbind").on("click",function(){
                $(".btn").off("click",flash)
                         .text("點擊無效");;
            });
            var flash=function(){
                $("div").show().fadeOut("slow");//先顯示,再緩慢隱藏
            }
        })
    </script>
    <style>
        div{ display: none; }
    </style>
</head>
<body>

<button class="btn">點擊無效</button>
<button class="bind">系結</button>
<button class="unbind">取消系結</button>
<div>按鈕被點擊了~</div>

</body>
</html>

 

 .one() 系結一次性的事件處理函式

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script src="jquery.js"></script>
    <script>
        $(function(){
            $(".bind").on("click",function(){
                $(".btn").on("click",flash)
                         .text("點擊有效");
            });
            $(".unbind").on("click",function(){
                $(".btn").off("click",flash)
                         .text("點擊無效");;
            });
            $(".bindOne").on("click",function(){
                $(".btn").one("click",flash)
                         .text("僅一次點擊有效");
            });
            var flash=function(){
                $("div").show().fadeOut("slow");//先顯示,再緩慢隱藏
            }
        })
    </script>
    <style>
        div{ display: none; }
    </style>
</head>
<body>

<button class="btn">點擊無效</button>
<button class="bind">系結</button>
<button class="unbind">取消系結</button>
<button class="bindOne">系結一次</button>
<div>按鈕被點擊了~</div>

</body>
</html>

 

 專案三大bug:

1、重繪后第一次按下左鍵無效,第二次按左鍵開始生效

原因:默認后面的覆寫前面的,因此顯示的是第4張;但是index是0,因此第一次按左鍵時,index變成了最后一張;視覺上看是沒有變化的

最簡單的解決方法:將 index 改為默認顯示的圖片,使之同步( index=0 改成 $("a").length-1)

2、重繪后默認是最后一張,按下右鍵,出來的圖片不是第一張,而是第二張

前面一個解決方法,同時解決了1和2兩個bug

3、左右幾次按鍵之后,輕輕一動滑鼠,圖片切換到了最后一張;滑鼠移出再移入時又到了最后一張

原因:$("a").add(document) 這種寫法導致程式無法判斷什么時候是針對a,什么時候是針對document,導致滑鼠在document上移動時也觸發了mouseenter事件

解決方法:判斷只有當觸發事件的元素的標簽名是a的時候,才進行切換


 

但是,一般專案中輪播圖默認都是從0開始的

解決:函式封裝需要初始化

專案index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>jquery</title>
    <link rel="stylesheet" href="style.css">
    <script src="jquery.js"></script>
    <script src="script.js"></script>
</head>
<body>
    <span class="top"></span>
    <nav>
        <a href="#">banner1</a>
        <a href="#">banner2</a>
        <a href="#">banner3</a>
        <a href="#">banner4</a>
    </nav>
    <div class="img-box">
        <img src="image/cat1.jpg">
        <img src="image/cat2.jpg">
        <img src="image/cat3.jpg">
        <img src="image/cat4.jpg">
    </div>
</body>
</html>

style.css

* { margin: 0; padding: 0; border: none; }
html, body { overflow: hidden;/*解決因為盒模型溢位造成的垂直方向滾動條*/ height: 100%; background-color: rgb(145, 176, 200); }
span.top { display: block; width: 16px; height: 16px; margin: 30px auto 40px; border-radius: 50%; background-color: #fff; }
nav { position: relative; display: flex;/*彈性盒模型*/ width: 40%; margin: 0 auto 45px; justify-content: space-between;/*實作元素在容器內左右均勻分布*/ }
nav:before { position: absolute; top: 20px; display: block; width: 100%; height: 10px; content: '';/*激活偽元素*/ background-color: #fff; }
nav > a { font-size: 14px; position: relative;    /*默認是static定位,會被絕對定位覆寫 修改為相對定位之后,會覆寫前面的元素*/ padding: 10px 20px; text-decoration: none; color: rgb(144, 146, 152); border: 2px solid rgb(144, 146, 152); background-color: #fff; }
.img-box { position: relative; overflow: hidden; width: 250px; height: 250px; margin: 0 auto; background-color: #fff; box-shadow: 0 0 30px 0 rgba(144, 146, 152, .3); }
.img-box img { position: absolute; top: 0; right: 0; bottom: 0; left: 0; width: 98%; margin: auto;/*以上5句實作絕對定位的居中*/ }
/*# sourceMappingURL=style.css.map */

script.js

$(function(){
    var index=$("a").length-1;

    //系結多個事件
    $("a").add(document).on({
        click:function(event){
            event.stopPropagation();//阻止冒泡
            index=$(this).index(); // 獲取當前點擊的a的index
            swiper();
        },
        mouseenter:function(event){
            event.stopPropagation();//阻止冒泡
            console.log($(this)[0].nodeName);//當前物件的標簽名
            if($(this)[0].nodeName=="A"){
                index=$(this).index(); // 獲取當前點擊的a的index
            }else{
                return true;
            }
            swiper();
        },
        keydown:function(event){
            if(event.keyCode==37){//
                index=index>0 ? --index : $("a").length-1;
            }else if(event.keyCode==39){//
                index=index<$("a").length-1 ? ++index : 0;
            }else{
                return true;
            }
            swiper();
        }
    });

    var swiper=function(){
        $("img").eq(index) 
                .css({"opacity":"1"})
                .siblings()
                .css({"opacity":"0"});
    }

    //初始化
    var init=function(){
        index=0;
        swiper();
    }
    init();

});

效果圖

 

轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/11174.html

標籤:jQuery

上一篇:jQuery的核心功能選擇器

下一篇:jQuery判斷checkbox是否選中的3種方法

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • IEEE1588PTP在數字化變電站時鐘同步方面的應用

    IEEE1588ptp在數字化變電站時鐘同步方面的應用 京準電子科技官微——ahjzsz 一、電力系統時間同步基本概況 隨著對IEC 61850標準研究的不斷深入,國內外學者提出基于IEC61850通信標準體系建設數字化變電站的發展思路。數字化變電站與常規變電站的顯著區別在于程序層傳統的電流/電壓互 ......

    uj5u.com 2020-09-10 03:51:52 more
  • HTTP request smuggling CL.TE

    CL.TE 簡介 前端通過Content-Length處理請求,通過反向代理或者負載均衡將請求轉發到后端,后端Transfer-Encoding優先級較高,以TE處理請求造成安全問題。 檢測 發送如下資料包 POST / HTTP/1.1 Host: ac391f7e1e9af821806e890 ......

    uj5u.com 2020-09-10 03:52:11 more
  • 網路滲透資料大全單——漏洞庫篇

    網路滲透資料大全單——漏洞庫篇漏洞庫 NVD ——美國國家漏洞庫 →http://nvd.nist.gov/。 CERT ——美國國家應急回應中心 →https://www.us-cert.gov/ OSVDB ——開源漏洞庫 →http://osvdb.org Bugtraq ——賽門鐵克 →ht ......

    uj5u.com 2020-09-10 03:52:15 more
  • 京準講述NTP時鐘服務器應用及原理

    京準講述NTP時鐘服務器應用及原理京準講述NTP時鐘服務器應用及原理 安徽京準電子科技官微——ahjzsz 北斗授時原理 授時是指接識訓通過某種方式獲得本地時間與北斗標準時間的鐘差,然后調整本地時鐘使時差控制在一定的精度范圍內。 衛星導航系統通常由三部分組成:導航授時衛星、地面檢測校正維護系統和用戶 ......

    uj5u.com 2020-09-10 03:52:25 more
  • 利用北斗衛星系統設計NTP網路時間服務器

    利用北斗衛星系統設計NTP網路時間服務器 利用北斗衛星系統設計NTP網路時間服務器 安徽京準電子科技官微——ahjzsz 概述 NTP網路時間服務器是一款支持NTP和SNTP網路時間同步協議,高精度、大容量、高品質的高科技時鐘產品。 NTP網路時間服務器設備采用冗余架構設計,高精度時鐘直接來源于北斗 ......

    uj5u.com 2020-09-10 03:52:35 more
  • 詳細解讀電力系統各種對時方式

    詳細解讀電力系統各種對時方式 詳細解讀電力系統各種對時方式 安徽京準電子科技官微——ahjzsz,更多資料請添加VX 衛星同步時鐘是我京準公司開發研制的應用衛星授時時技術的標準時間顯示和發送的裝置,該裝置以M國全球定位系統(GLOBAL POSITIONING SYSTEM,縮寫為GPS)或者我國北 ......

    uj5u.com 2020-09-10 03:52:45 more
  • 如何保證外包團隊接入企業內網安全

    不管企業規模的大小,只要企業想省錢,那么企業的某些服務就一定會采用外包的形式,然而看似美好又經濟的策略,其實也有不好的一面。下面我通過安全的角度來聊聊使用外包團的安全隱患問題。 先看看什么服務會使用外包的,最常見的就是話務/客服這種需要大量重復性、無技術性的服務,或者是一些銷售外包、特殊的職能外包等 ......

    uj5u.com 2020-09-10 03:52:57 more
  • PHP漏洞之【整型數字型SQL注入】

    0x01 什么是SQL注入 SQL是一種注入攻擊,通過前端帶入后端資料庫進行惡意的SQL陳述句查詢。 0x02 SQL整型注入原理 SQL注入一般發生在動態網站URL地址里,當然也會發生在其它地發,如登錄框等等也會存在注入,只要是和資料庫打交道的地方都有可能存在。 如這里http://192.168. ......

    uj5u.com 2020-09-10 03:55:40 more
  • [GXYCTF2019]禁止套娃

    git泄露獲取原始碼 使用GET傳參,引數為exp 經過三層過濾執行 第一層過濾偽協議,第二層過濾帶引數的函式,第三層過濾一些函式 preg_replace('/[a-z,_]+\((?R)?\)/', NULL, $_GET['exp'] (?R)參考當前正則運算式,相當于匹配函式里的引數 因此傳遞 ......

    uj5u.com 2020-09-10 03:56:07 more
  • 等保2.0實施流程

    流程 結論 ......

    uj5u.com 2020-09-10 03:56:16 more
最新发布
  • 使用Django Rest framework搭建Blog

    在前面的Blog例子中我們使用的是GraphQL, 雖然GraphQL的使用處于上升趨勢,但是Rest API還是使用的更廣泛一些. 所以還是決定回到傳統的rest api framework上來, Django rest framework的官網上給了一個很好用的QuickStart, 我參考Qu ......

    uj5u.com 2023-04-20 08:17:54 more
  • 記錄-new Date() 我忍你很久了!

    這里給大家分享我在網上總結出來的一些知識,希望對大家有所幫助 大家平時在開發的時候有沒被new Date()折磨過?就是它的諸多怪異的設定讓你每每用的時候,都可能不小心踩坑。造成程式意外出錯,卻一下子找不到問題出處,那叫一個煩透了…… 下面,我就列舉它的“四宗罪”及應用思考 可惡的四宗罪 1. Sa ......

    uj5u.com 2023-04-20 08:17:47 more
  • 使用Vue.js實作文字跑馬燈效果

    實作文字跑馬燈效果,首先用到 substring()截取 和 setInterval計時器 clearInterval()清除計時器 效果如下: 實作代碼如下: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta ......

    uj5u.com 2023-04-20 08:12:31 more
  • JavaScript 運算子

    JavaScript 運算子/運算子 在 JavaScript 中,有一些運算子可以使代碼更簡潔、易讀和高效。以下是一些常見的運算子: 1、可選鏈運算子(optional chaining operator) ?.是可選鏈運算子(optional chaining operator)。?. 可選鏈操 ......

    uj5u.com 2023-04-20 08:02:25 more
  • CSS—相對單位rem

    一、概述 rem是一個相對長度單位,它的單位長度取決于根標簽html的字體尺寸。rem即root em的意思,中文翻譯為根em。瀏覽器的文本尺寸一般默認為16px,即默認情況下: 1rem = 16px rem布局原理:根據CSS媒體查詢功能,更改根標簽的字體尺寸,實作rem單位隨螢屏尺寸的變化,如 ......

    uj5u.com 2023-04-20 08:02:21 more
  • 我的第一個NPM包:panghu-planebattle-esm(胖虎飛機大戰)使用說明

    好家伙,我的包終于開發完啦 歡迎使用胖虎的飛機大戰包!! 為你的主頁添加色彩 這是一個有趣的網頁小游戲包,使用canvas和js開發 使用ES6模塊化開發 效果圖如下: (覺得圖片太sb的可以自己改) 代碼已開源!! Git: https://gitee.com/tang-and-han-dynas ......

    uj5u.com 2023-04-20 08:01:50 more
  • 如何在 vue3 中使用 jsx/tsx?

    我們都知道,通常情況下我們使用 vue 大多都是用的 SFC(Signle File Component)單檔案組件模式,即一個組件就是一個檔案,但其實 Vue 也是支持使用 JSX 來撰寫組件的。這里不討論 SFC 和 JSX 的好壞,這個仁者見仁智者見智。本篇文章旨在帶領大家快速了解和使用 Vu ......

    uj5u.com 2023-04-20 08:01:37 more
  • 【Vue2.x原始碼系列06】計算屬性computed原理

    本章目標:計算屬性是如何實作的?計算屬性快取原理以及洋蔥模型的應用?在初始化Vue實體時,我們會給每個計算屬性都創建一個對應watcher,我們稱之為計算屬性watcher ......

    uj5u.com 2023-04-20 08:01:31 more
  • http1.1與http2.0

    一、http是什么 通俗來講,http就是計算機通過網路進行通信的規則,是一個基于請求與回應,無狀態的,應用層協議。常用于TCP/IP協議傳輸資料。目前任何終端之間任何一種通信方式都必須按Http協議進行,否則無法連接。tcp(三次握手,四次揮手)。 請求與回應:客戶端請求、服務端回應資料。 無狀態 ......

    uj5u.com 2023-04-20 08:01:10 more
  • http1.1與http2.0

    一、http是什么 通俗來講,http就是計算機通過網路進行通信的規則,是一個基于請求與回應,無狀態的,應用層協議。常用于TCP/IP協議傳輸資料。目前任何終端之間任何一種通信方式都必須按Http協議進行,否則無法連接。tcp(三次握手,四次揮手)。 請求與回應:客戶端請求、服務端回應資料。 無狀態 ......

    uj5u.com 2023-04-20 08:00:32 more