(待續(xù)ing)一、示例
二、技巧解說1、界面背景圖鎖定【效果描述】:背景圖固定不動(dòng)(就像貼在 最底下的圖),其余頁面內(nèi)容可以在其上方正常翻動(dòng)瀏覽(鏤空設(shè)計(jì))(待續(xù))
2、固定定位——敵動(dòng)我不動(dòng)【效果描述】:網(wǎng)頁固定不動(dòng)的部件,例如:【CSS】(1)網(wǎng)頁固定部件:使用的是 CSS的固定定位 —— position: fixed;例如:該部件屬于 box 類,為其添加屬性 position: fixed;.box { position: fixed; top: 10px; left: 20px; }
(2)返回頂部(頁面瀏覽到一定位置后,出現(xiàn)“返回頂部”小標(biāo)簽) (jQuery事件)<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <link href="https://cdn./twitter-bootstrap/3.4.1/css/bootstrap.min.css" rel="stylesheet"> <script src="https://cdn./jquery/3.3.1/jquery.min.js"></script> <script src="https://cdn./twitter-bootstrap/3.4.1/js/bootstrap.min.js"></script> <style> .hide { display: none; } #d1 { position: fixed; background-color: black; right: 20px; bottom: 20px; height: 50px; width: 50px; } </style> </head> <body> <a href="" id="d1"></a> <div style="height: 500px;background-color: red"></div> <div style="height: 500px;background-color: greenyellow"></div> <div style="height: 500px;background-color: blue"></div> <a href="#d1" class="hide">回到頂部</a> <script> $(window).scroll(function () { if($(window).scrollTop() > 300){ $('#d1').removeClass('hide') }else{ $('#d1').addClass('hide') } }) </script> </body> </html>
3、鏈接四狀態(tài)——訪問前,懸浮,點(diǎn)擊時(shí),訪問后【效果描述】:鼠標(biāo)懸浮,文字或者圖片有顏色變化 / 小小的浮動(dòng)突出【CSS】(1)四狀態(tài)顏色變化(具體應(yīng)用 參考示例的-超級(jí)無敵簡易版博客園-).title a:link { color:forestgreen; } .title a:hover { color:pink; } .title a:active { color:olivedrab; } .title a:visited { color:black; } (2)動(dòng)畫效果(待續(xù))
4、顯隱菜單【jQuery 版本】<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <link href="https://cdn./twitter-bootstrap/3.4.1/css/bootstrap.min.css" rel="stylesheet"> <script src="https://cdn./jquery/3.3.1/jquery.min.js"></script> <script src="https://cdn./twitter-bootstrap/3.4.1/js/bootstrap.min.js"></script> <style> .left { float: left; background-color: darkgray; width: 20%; height: 100%; position: fixed; } .title { font-size: 36px; color: white; text-align: center; } .items { border: 1px solid black; } .hide { display: none; } </style> </head> <body> <div class="left"> <div class="menu"> <div class="title">菜單一 <div class="items">111</div> <div class="items">222</div> <div class="items">333</div> </div> <div class="title">菜單二 <div class="items">111</div> <div class="items">222</div> <div class="items">333</div> </div> <div class="title">菜單三 <div class="items">111</div> <div class="items">222</div> <div class="items">333</div> </div> </div> </div> <script> $('.title').click(function () { // 先給所有的items加hide $('.items').addClass('hide') // 然后將被點(diǎn)擊標(biāo)簽內(nèi)部的hide移除 $(this).children().removeClass('hide') }) </script> </body> </html>
(待續(xù))
5、登入注冊(cè)相關(guān)事件(jQuery事件)(1)自定義登入校驗(yàn)——【jQuery 版本】<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <link href="https://cdn./twitter-bootstrap/3.4.1/css/bootstrap.min.css" rel="stylesheet"> <script src="https://cdn./jquery/3.3.1/jquery.min.js"></script> <script src="https://cdn./twitter-bootstrap/3.4.1/js/bootstrap.min.js"></script> </head> <body> <p>username: <input type="text" id="username"> <span style="color: red"></span> </p> <p>password: <input type="text" id="password"> <span style="color: red"></span> </p> <button id="d1">提交</button> <script> let $userName = $('#username') let $passWord = $('#password') $('#d1').click(function () { // 獲取用戶輸入的用戶名和密碼 做校驗(yàn) let userName = $userName.val() let passWord = $passWord.val() if (!userName){ $userName.next().text("用戶名不能為空") } if (!passWord){ $passWord.next().text('密碼不能為空') } }) $('input').focus(function () { $(this).next().text('') }) </script> </body> </html> (2)input 框 實(shí)時(shí)監(jiān)控(即 實(shí)時(shí)監(jiān)控用戶輸入的內(nèi)容,例如 判斷用戶名是否已被占用,密碼格式是否正確 等)<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>k</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <link href="https://cdn./twitter-bootstrap/3.4.1/css/bootstrap.min.css" rel="stylesheet"> <script src="https://cdn./jquery/3.3.1/jquery.min.js"></script> <script src="https://cdn./twitter-bootstrap/3.4.1/js/bootstrap.min.js"></script> </head> <body> <input type="text" id="d1"> <script> $('#d1').on('input',function () { console.log(this.value) }) </script> </body> </html>
6、克隆事件(jQuery事件)(點(diǎn)擊標(biāo)簽,就可以復(fù)制標(biāo)簽)<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <link href="https://cdn./twitter-bootstrap/3.4.1/css/bootstrap.min.css" rel="stylesheet"> <script src="https://cdn./jquery/3.3.1/jquery.min.js"></script> <script src="https://cdn./twitter-bootstrap/3.4.1/js/bootstrap.min.js"></script> <style> #d1 { height: 100px; width: 100px; background-color: orange; border: 1px solid blue; } </style> </head> <body> <button id="d1">屠龍寶刀,點(diǎn)擊就送</button> <script> $('#d1').on('click',function () { // console.log(this) // this指代是當(dāng)前被操作的標(biāo)簽對(duì)象 // $(this).clone().insertAfter($('body')) // clone默認(rèn)情況下只克隆html和css 不克隆事件 $(this).clone(true).insertAfter($('body')) // 括號(hào)內(nèi)加true即可克隆事件 }) </script> </body> </html> 7、模態(tài)框事件(jQuery事件)(例如 百度登入界面 三層視圖結(jié)構(gòu))<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8"> <meta http-equiv="x-ua-compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>自定義模態(tài)框</title> <style> .cover { position: fixed; left: 0; right: 0; top: 0; bottom: 0; background-color: darkgrey; z-index: 999; } .modal { width: 600px; height: 400px; background-color: white; position: fixed; left: 50%; top: 50%; margin-left: -300px; margin-top: -200px; z-index: 1000; } .hide { display: none; } </style> </head> <body> <input type="button" value="彈" id="i0"> <div class="cover hide"></div> <div class="modal hide"> <label for="i1">姓名</label> <input id="i1" type="text"> <label for="i2">愛好</label> <input id="i2" type="text"> <input type="button" id="i3" value="關(guān)閉"> </div> <script src="https://cdn./jquery/3.2.1/jquery.min.js"></script> <script> // var tButton = $("#i0")[0]; $("#i0").click(function () { var coverEle = $(".cover")[0]; // 需要手動(dòng)轉(zhuǎn) var modalEle = $(".modal")[0]; $(coverEle).removeClass("hide"); $(modalEle).removeClass("hide"); }) // tButton.onclick=function () { // var coverEle = $(".cover")[0]; // var modalEle = $(".modal")[0]; // // $(coverEle).removeClass("hide"); // $(modalEle).removeClass("hide"); // }; var cButton = $("#i3")[0]; cButton.onclick=function () { var coverEle = $(".cover")[0]; var modalEle = $(".modal")[0]; $(coverEle).addClass("hide"); $(modalEle).addClass("hide"); } </script> </body> </html> 8、hover事件(jQuery事件)(鼠標(biāo)懸浮在目標(biāo)標(biāo)簽 與 離開標(biāo)簽)<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <link href="https://cdn./twitter-bootstrap/3.4.1/css/bootstrap.min.css" rel="stylesheet"> <script src="https://cdn./jquery/3.3.1/jquery.min.js"></script> <script src="https://cdn./twitter-bootstrap/3.4.1/js/bootstrap.min.js"></script> </head> <body> <p id="d1">到家啊就是度假酒店</p> <script> // $("#d1").hover(function () { // 鼠標(biāo)懸浮 + 鼠標(biāo)移開 // alert(123) // }) $('#d1').hover( function () { alert('我來了') // 懸浮 }, function () { alert('我溜了') // 移開 } ) </script> </body> </html> 9、鍵盤按鍵事件 (jQuery事件)(實(shí)時(shí)提示 你按下了什么鍵(鍵盤的每個(gè)按鍵,在jQuery框架中,都有相應(yīng)的數(shù)字編號(hào))<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <link href="https://cdn./twitter-bootstrap/3.4.1/css/bootstrap.min.css" rel="stylesheet"> <script src="https://cdn./jquery/3.3.1/jquery.min.js"></script> <script src="https://cdn./twitter-bootstrap/3.4.1/js/bootstrap.min.js"></script> </head> <body> <script> $(window).keydown(function (event) { console.log(event.keyCode) if (event.keyCode === 16){ alert('你按了shift鍵') } }) </script> </body> </html>
10、趣味小功能——點(diǎn)贊+1參考:https://v3./components/#badges <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>good+1</title> <link href="https://cdn./twitter-bootstrap/3.4.1/css/bootstrap.min.css" rel="stylesheet"> <link rel="stylesheet" href="font-awesome-4.7.0/css/font-awesome.min.css"> <script src="https://cdn./jquery/3.3.1/jquery.min.js"></script> <script src="https://cdn./twitter-bootstrap/3.4.1/js/bootstrap.min.js"></script> <link rel="stylesheet" href="bootstrap-sweetalert-master/dist/sweetalert.css"> <script src="bootstrap-sweetalert-master/dist/sweetalert.min.js"></script> </head> <body> <!-- 樣式1 --> <!-- <a href="#">Inbox <span class="badge">42</span></a> <button class="btn btn-primary" type="button"> Messages <span class="badge">4</span> </button> --> <!-- 樣式2 --> <!-- <ul class="nav nav-pills" role="tablist"> <li role="presentation" class="active"><a href="#">Home <span class="badge">42</span></a></li> <li role="presentation"><a href="#">Profile</a></li> <li role="presentation"><a href="#">Messages <span class="badge">3</span></a></li> </ul> --> <!-- 版本3 good+1 --> <div class="container"> <button type="button" id="btn-good" class="btn btn-success"> (~ ̄▽ ̄)~ <!-- # class="fa fa-thumbs-up" 點(diǎn)贊圖標(biāo)--> <i class="fa fa-heart" aria-hidden="true"></i> <span class="badge badge-light" id="good-value">0</span> </button> </div> <script> let $goodEle = $('#good-value'); $('#btn-good').click(function () { let oldNum = $goodEle.text(); // parseInt() 函數(shù)是 JavaScript函數(shù),可解析一個(gè)字符串,并返回一個(gè)整數(shù)。 let newNum = parseInt(oldNum)+1; $goodEle.text(`${newNum}`); swal("THANKS FOR YOUR |
|