jQuery實(shí)現(xiàn)右下角可縮放大小的層完整實(shí)例
本文實(shí)例講述了jQuery實(shí)現(xiàn)右下角可縮放大小的層。分享給大家供大家參考,具體如下:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>大小可縮放層測試</title> <script type = "text/javascript" src="jquery-1.7.2.js"></script> <style type = "text/css"> #fa{ border:1px solid blue; overflow:auto; width:400px; height:400px; } #main{ margin:0; padding:0; width:300px; height:280px; border:1px solid red; } </style> <script type = "text/javascript"> $(function(){ var div = getObj("main"); div.onmousemove = function(e){ var e = e || window.event; var posx = e.clientX; var posy = e.clientY; var l = div.offsetLeft; var t = div.offsetTop; var h = div.clientHeight; var w = div.clientWidth; var ol = l+w-10; var or = l+w+10; var ot = t+h-10; var ob = t+h+10; this.style.cursor = ""; if(posx>ol && posx<or && posy >ot && posy<ob){ div.style.cursor = "nw-resize"; } } div.onmousedown = function(e){ var e = e || window.event; var initX = e.clientX; var initY = e.clientY; var l = div.offsetLeft; var t = div.offsetTop; var h = div.clientHeight; var w = div.clientWidth; var ol = l+w-10; var or = l+w+10; var ot = t+h-10; var ob = t+h+10; if(initX>ol && initX<or && initY >ot && initY<ob){ document.onmousemove = function(evt){ var e = evt || window.event; var currX = e.clientX; var currY = e.clientY; div.style.width = w + (currX - initX)+"px"; div.style.height = h+(currY-initY)+"px"; } document.onmouseup = function(){ document.onmousemove = null; document.onmouseup = null; } } } }); function getObj(id){ return document.getElementById(id); } </script> </head> <body> <div id = "fa"> <div id = "main"></div> </div> </body> </html>
函數(shù)封裝后:
function resize(div){ div.mousemove(function(e){ var e = e || window.event; var posx = e.clientX; var posy = e.clientY; var l = div.offset().left; var t = div.offset().top; var h = div.height(); var w = div.width(); var ol = l+w-10; var or = l+w+10; var ot = t+h-10; var ob = t+h+10; $(this).css("cursor",""); if(posx>ol && posx<or && posy >ot && posy<ob){ $(this).css("cursor","nw-resize"); } }); div.mousedown(function(e){ var e = e || window.event; var posx = e.clientX; var posy = e.clientY; var l = div.offset().left; var t = div.offset().top; var h = div.height(); var w = div.width(); var ol = l+w-10; var or = l+w+10; var ot = t+h-10; var ob = t+h+10; if(posx>=ol && posx<=or && posy >=ot && posy<=ob){ document.onmousemove = function(e){ var e = e || window.event; var currX = e.clientX; var currY = e.clientY; div.width(w + (currX - posx)); div.height(h+(currY-posy)); } $(document).mouseup(function(){ document.onmousemove = null; }); } }); }
更多關(guān)于jQuery相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《jQuery表格(table)操作技巧匯總》、《jQuery常用插件及用法總結(jié)》、《jquery中Ajax用法總結(jié)》、《jQuery拖拽特效與技巧總結(jié)》、《jQuery擴(kuò)展技巧總結(jié)》、《jQuery常見經(jīng)典特效匯總》、《jQuery動(dòng)畫與特效用法總結(jié)》及《jquery選擇器用法總結(jié)》
希望本文所述對(duì)大家jQuery程序設(shè)計(jì)有所幫助。
- jquery右下角自動(dòng)彈出可關(guān)閉的廣告層
- 基于jQuery的網(wǎng)頁右下角彈出廣告(IE7,firefox)
- jQuery實(shí)現(xiàn)的網(wǎng)頁右下角tab樣式在線客服效果代碼
- jquery實(shí)現(xiàn)浮動(dòng)在網(wǎng)頁右下角的彩票開獎(jiǎng)公告窗口代碼
- JQUERY實(shí)現(xiàn)網(wǎng)頁右下角固定位置展開關(guān)閉特效的方法
- jquery右下角彈出提示框示例代碼
- Jquery右下角抖動(dòng)、浮動(dòng) 實(shí)例代碼(兼容ie6、FF)
- jQuery 右下角滑動(dòng)彈出可關(guān)閉重現(xiàn)層完整代碼
- 基于jQuery的message插件實(shí)現(xiàn)右下角彈出消息框
- jQuery實(shí)現(xiàn)的右下角廣告窗體跟隨效果示例
相關(guān)文章
jQuery判斷checkbox(復(fù)選框)是否被選中以及全選、反選實(shí)現(xiàn)代碼
本篇文章主要是對(duì)jQuery判斷checkbox(復(fù)選框)是否被選中以及全選、反選實(shí)現(xiàn)代碼進(jìn)行了介紹,需要的朋友可以過來參考下,希望對(duì)大家有所幫助2014-02-02jQuery實(shí)現(xiàn)鼠標(biāo)滑向當(dāng)前圖片高亮顯示并且其它圖片變灰的方法
這篇文章主要介紹了jQuery實(shí)現(xiàn)鼠標(biāo)滑向當(dāng)前圖片高亮顯示并且其它圖片變灰的方法,涉及jquery鏈?zhǔn)讲僮骷绊撁嬖貥邮娇刂频南嚓P(guān)技巧,需要的朋友可以參考下2015-07-07基于jquery實(shí)現(xiàn)手風(fēng)琴效果
這篇文章主要為大家詳細(xì)介紹了基于jquery實(shí)現(xiàn)手風(fēng)琴效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-04-04jQuery實(shí)現(xiàn)對(duì)象轉(zhuǎn)為url參數(shù)的方法
這篇文章主要介紹了jQuery實(shí)現(xiàn)對(duì)象轉(zhuǎn)為url參數(shù)的方法,涉及jQuery針對(duì)字符串的遍歷與轉(zhuǎn)換操作相關(guān)技巧,需要的朋友可以參考下2017-01-01jquery 倒計(jì)時(shí)效果實(shí)現(xiàn)秒殺思路
公司做了個(gè)秒殺頁面,需要做一個(gè)倒計(jì)時(shí)效果,感覺還特此收藏,喜歡的朋友也可以學(xué)習(xí)下2013-09-09jquery.autocomplete修改實(shí)現(xiàn)鍵盤上下鍵自動(dòng)填充示例
根據(jù)需求要實(shí)現(xiàn)通過鍵盤上下移動(dòng),獲得聯(lián)想菜單中的值,如同google baidu的查詢功能,下面的代碼是自己手寫的,喜歡的朋友可以嘗試操作下2013-11-11jQuery AJAX應(yīng)用實(shí)例總結(jié)
這篇文章主要介紹了jQuery AJAX應(yīng)用,結(jié)合實(shí)例形式總結(jié)分析了jQuery 使用AJAX訪問各種格式數(shù)據(jù)相關(guān)應(yīng)用操作實(shí)現(xiàn)技巧,需要的朋友可以參考下2020-05-05