最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

JavaScript+CSS實(shí)現(xiàn)模態(tài)框效果

 更新時(shí)間:2022年07月04日 09:59:26   作者:weixin_44607194  
這篇文章主要為大家詳細(xì)介紹了JavaScript+CSS實(shí)現(xiàn)模態(tài)框效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了JavaScript+CSS實(shí)現(xiàn)模態(tài)框效果的具體代碼,供大家參考,具體內(nèi)容如下

發(fā)現(xiàn)的問(wèn)題

1)鼠標(biāo)按下后拖動(dòng)的瞬間,光標(biāo)會(huì)脫離模態(tài)盒子跑到外面
2)鼠標(biāo)彈起事件不起作用

解決的思路

首先是因?yàn)榇a里有用到offsetLeft和offsetTop這兩個(gè)屬性,所以考慮是不是模態(tài)框的定位出現(xiàn)了問(wèn)題 。

又:設(shè)置關(guān)閉標(biāo)簽設(shè)置了絕對(duì)定位,那么loginBox作為其父級(jí)元素我將其設(shè)置為相對(duì)定位

各個(gè)類(lèi)型定位的介紹:

1.靜態(tài)定位: position: static 默認(rèn),也就是文檔流定位,元素的顯示位置與源碼順序一致(不是定位元素)

2.相對(duì)定位: position: relative;相對(duì)于該元素在文檔流中的原始位置進(jìn)行偏移

3.絕對(duì)定位: position: absolue;相對(duì)于它的祖先中離它最近的”定位元素”的位置發(fā)生偏移(如果祖先元素中不存在定位元素,它就參考根元素(html)進(jìn)行定位)

4.固定定位: position: fixed; 是絕對(duì)定位的一個(gè)特例,它始終相對(duì)于html定位

定位元素:只要這個(gè)元素中有position: relative;或者 position:absolute;就稱(chēng)為定位元素

由上可看出,相對(duì)定位,指的是相對(duì)于該元素在文檔流中的原始位置進(jìn)行偏移而不是相對(duì)于html,所以loginBox不能設(shè)置為相對(duì)定位??梢杂媒^對(duì)定位或固定定位,兩者均可。

另外,需要注意使用top、left定位后,則margin-top、margin-left產(chǎn)生同方向相加的位移效果,margin-bottom、margin-righ產(chǎn)生無(wú)任何效果的margin空間。所以保留margin: 100px auto;時(shí)效果還是會(huì)有些奇怪,注釋起來(lái)了就好了。

代碼

<!DOCTYPE html>
<html lang="en">

<head>
? ? <meta charset="UTF-8">
? ? <meta name="viewport" content="width=device-width, initial-scale=1.0">
? ? <title>Document</title>
? ? <style>
? ? ? ? * {
? ? ? ? ? ? padding: 0;
? ? ? ? ? ? margin: 0;
? ? ? ? }
? ? ? ??
? ? ? ? body {
? ? ? ? ? ? background-color: white;
? ? ? ? }
? ? ? ??
? ? ? ? .dianji {
? ? ? ? ? ? height: 50px;
? ? ? ? ? ? width: 300px;
? ? ? ? ? ? font-size: 20px;
? ? ? ? ? ? margin: 10px auto;
? ? ? ? ? ? cursor: pointer;
? ? ? ? }
? ? ? ??
? ? ? ? .loginBox {
? ? ? ? ? ? position: absolute;
? ? ? ? ? ? top: 50%;
? ? ? ? ? ? left: 50%;
? ? ? ? ? ? transform: translate(-50%, -50%);
? ? ? ? ? ? /* margin: 100px auto; */
? ? ? ? ? ? box-sizing: border-box;
? ? ? ? ? ? height: 200px;
? ? ? ? ? ? width: 370px;
? ? ? ? ? ? background-color: white;
? ? ? ? ? ? text-align: center;
? ? ? ? ? ? display: none;
? ? ? ? }
? ? ? ??
? ? ? ? .loginBox>span {
? ? ? ? ? ? position: absolute;
? ? ? ? ? ? top: -15px;
? ? ? ? ? ? right: -15px;
? ? ? ? ? ? height: 30px;
? ? ? ? ? ? width: 30px;
? ? ? ? ? ? font-size: 8px;
? ? ? ? ? ? line-height: 30px;
? ? ? ? ? ? border-radius: 50%;
? ? ? ? ? ? background-color: white;
? ? ? ? ? ? border: 1px solid #cccccc;
? ? ? ? }
? ? ? ??
? ? ? ? .loginBox h5 {
? ? ? ? ? ? /* position: relative; */
? ? ? ? ? ? margin-bottom: 18px;
? ? ? ? ? ? font-weight: normal;
? ? ? ? ? ? font-size: 16px;
? ? ? ? ? ? cursor: move;
? ? ? ? }
? ? ? ??
? ? ? ? .uname {
? ? ? ? ? ? margin: 18px 0 15px 15px;
? ? ? ? ? ? height: 25px;
? ? ? ? ? ? line-height: 25px;
? ? ? ? }
? ? ? ??
? ? ? ? .uname span,
? ? ? ? .psw span {
? ? ? ? ? ? font-size: 12px;
? ? ? ? }
? ? ? ??
? ? ? ? .uname input,
? ? ? ? .psw input {
? ? ? ? ? ? height: 25px;
? ? ? ? ? ? width: 230px;
? ? ? ? ? ? font-size: 12px;
? ? ? ? ? ? outline: none;
? ? ? ? }
? ? ? ??
? ? ? ? .loginBox button {
? ? ? ? ? ? margin: 20px;
? ? ? ? ? ? width: 190px;
? ? ? ? ? ? height: 30px;
? ? ? ? ? ? border: 1px solid #cccccc;
? ? ? ? }
? ? </style>
</head>

<body>
? ? <div class="dianji">點(diǎn)擊,彈出登錄框</div>
? ? <div class="loginBox">
? ? ? ? <span class="close">關(guān)閉</span>
? ? ? ? <h5>登錄會(huì)員</h5>
? ? ? ? <div class="uname"><span>用戶(hù)名:</span> <input type="text" placeholder="請(qǐng)輸入用戶(hù)名"></div>
? ? ? ? <div class="psw"><span>登錄密碼:</span> <input type="password" placeholder="請(qǐng)輸入密碼"></div>
? ? ? ? <button>登錄</button>
? ? </div>
? ? <script>
? ? ? ? var dianji = document.querySelector('.dianji');
? ? ? ? var loginBox = document.querySelector('.loginBox');
? ? ? ? var close = document.querySelector('.close');
? ? ? ? var bodyy = document.body;
? ? ? ? var move_area = document.querySelector('h5');
? ? ? ? dianji.addEventListener('click', function() {
? ? ? ? ? ? bodyy.style.backgroundColor = '#ccc';
? ? ? ? ? ? loginBox.style.display = 'block';
? ? ? ? })
? ? ? ? close.addEventListener('click', function() {
? ? ? ? ? ? bodyy.style.backgroundColor = 'white';
? ? ? ? ? ? loginBox.style.display = 'none';
? ? ? ? })
? ? ? ? move_area.addEventListener('mousedown', function(e) {
? ? ? ? ? ? var x = e.pageX - loginBox.offsetLeft;
? ? ? ? ? ? var y = e.pageY - loginBox.offsetTop;
? ? ? ? ? ? console.log('x=' + x + ' ?y=' + y);
? ? ? ? ? ? document.addEventListener('mousemove', move)

? ? ? ? ? ? function move(e) {
? ? ? ? ? ? ? ? loginBox.style.left = e.pageX - x + 'px';
? ? ? ? ? ? ? ? loginBox.style.top = e.pageY - y + 'px';
? ? ? ? ? ? }
? ? ? ? ? ? //鼠標(biāo)彈起,就是讓鼠標(biāo)移動(dòng)時(shí)間解除
? ? ? ? ? ? document.addEventListener('mouseup', function() {
? ? ? ? ? ? ? ? document.removeEventListener('mousemove', move);
? ? ? ? ? ? })
? ? ? ? })
? ? </script>
</body>

</html>

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 基于JS實(shí)現(xiàn)導(dǎo)航條之調(diào)用網(wǎng)頁(yè)助手小精靈的方法

    基于JS實(shí)現(xiàn)導(dǎo)航條之調(diào)用網(wǎng)頁(yè)助手小精靈的方法

    在網(wǎng)站中加入網(wǎng)頁(yè)助手小精靈,當(dāng)用戶(hù)訪(fǎng)問(wèn)網(wǎng)站時(shí),向用戶(hù)問(wèn)好,或是傳遞一些網(wǎng)站的重要信息,給用戶(hù)帶來(lái)極好的體驗(yàn)感,那么基于js代碼是如何調(diào)用網(wǎng)頁(yè)助手小精靈的呢?下面跟著腳本之家小編一起學(xué)習(xí)吧
    2016-06-06
  • JS實(shí)現(xiàn)的仿淘寶交易倒計(jì)時(shí)效果

    JS實(shí)現(xiàn)的仿淘寶交易倒計(jì)時(shí)效果

    這篇文章主要介紹了JS實(shí)現(xiàn)的仿淘寶交易倒計(jì)時(shí)效果,涉及JavaScript針對(duì)時(shí)間與日期的動(dòng)態(tài)操作技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-11-11
  • js異步上傳多張圖片插件的使用方法

    js異步上傳多張圖片插件的使用方法

    這篇文章主要為大家詳細(xì)介紹了js異步上傳多張圖片插件的使用方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-10-10
  • Javascript實(shí)現(xiàn)跑馬燈效果的簡(jiǎn)單實(shí)例

    Javascript實(shí)現(xiàn)跑馬燈效果的簡(jiǎn)單實(shí)例

    下面小編就為大家?guī)?lái)一篇Javascript實(shí)現(xiàn)跑馬燈效果的簡(jiǎn)單實(shí)例。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2016-05-05
  • 教你巧用?import.meta?實(shí)現(xiàn)熱更新的問(wèn)題

    教你巧用?import.meta?實(shí)現(xiàn)熱更新的問(wèn)題

    import.meta?是一個(gè)給?JavaScript?模塊暴露特定上下文的元數(shù)據(jù)屬性的對(duì)象,它包含了這個(gè)模塊的信息,這篇文章主要介紹了巧用?import.meta?實(shí)現(xiàn)熱更新的問(wèn)題,需要的朋友可以參考下
    2022-04-04
  • ES6實(shí)現(xiàn)圖片切換特效代碼

    ES6實(shí)現(xiàn)圖片切換特效代碼

    這篇文章主要介紹了ES6實(shí)現(xiàn)圖片切換特效代碼,代碼簡(jiǎn)單易懂,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-01-01
  • js實(shí)現(xiàn)的GridView即表頭固定表體有滾動(dòng)條且可滾動(dòng)

    js實(shí)現(xiàn)的GridView即表頭固定表體有滾動(dòng)條且可滾動(dòng)

    實(shí)現(xiàn)GridView,表頭固定,表體有滾動(dòng)條且可滾動(dòng),下面有個(gè)不錯(cuò)的示例,希望對(duì)大家有所幫助
    2014-02-02
  • js修改input的type屬性問(wèn)題探討

    js修改input的type屬性問(wèn)題探討

    當(dāng)input元素還未插入文檔流之前,是可以修改它的值的,在ie和ff下都沒(méi)問(wèn)題。但如果input已經(jīng)存在于頁(yè)面,其type屬性在ie下就成了只讀屬性了,不可以修改
    2013-10-10
  • IE6彈出“已終止操作”的解決辦法

    IE6彈出“已終止操作”的解決辦法

    導(dǎo)致這個(gè)問(wèn)題產(chǎn)生的原因,一般是因?yàn)閖s(一個(gè)比較復(fù)雜的js)寫(xiě)在body里面,在body元素加載完之前調(diào)用出現(xiàn)問(wèn)題。顯然,解決該問(wèn)題的方法就是將這一段js放在body元素解析完畢之后。
    2010-11-11
  • 小程序登錄態(tài)管理的方法示例

    小程序登錄態(tài)管理的方法示例

    這篇文章主要介紹了小程序登錄態(tài)管理的方法示例,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-11-11

最新評(píng)論

兴业县| 海林市| 山丹县| 夹江县| 广安市| 堆龙德庆县| 孟津县| 京山县| 吕梁市| 曲阳县| 梧州市| 东光县| 临沧市| 崇礼县| 韶关市| 怀柔区| 疏附县| 雷波县| 麻江县| 沾化县| 宜兰县| 牡丹江市| 广南县| 岗巴县| 宜丰县| 西城区| 巧家县| 桃园市| 邹城市| 南华县| 平凉市| 游戏| 长乐市| 瑞昌市| 新源县| 寿光市| 进贤县| 屯门区| 疏勒县| 广饶县| 保康县|