jQuery實(shí)現(xiàn)Div拖動(dòng)+鍵盤控制綜合效果的方法
本文實(shí)例講述了jQuery實(shí)現(xiàn)Div拖動(dòng)+鍵盤控制綜合效果的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>jQuery Div拖動(dòng)+鍵盤控制綜合效果</title>
<meta http-equiv="content-type" content="text/html;charset=gb2312">
<script src="/ajaxjs/jquery1.3.2.js"></script>
</head>
<body>
預(yù)覽時(shí)看不到效果,刷新一下即可
<div id="text" style="width:120px;height:60px;background:#F06;position:absolute;left:500px;top:90px;cursor:move;"></div>
<script type="text/javascript">
var msgObj = document.getElementById('text');
var posx = 0;
var posy = 0;
var moveable = false;
var MouseDownEvent = document.onmousedown;
var MouseMoveEvent = document.onmousemove;
var MouseUpEvent = document.onmouseup;
msgObj.onmousedown = function(evt) {
var evt = evt||window.event;
moveable = true;
posy = evt.clientY-parseInt(msgObj.style.top);
posx = evt.clientX-parseInt(msgObj.style.left);
document.onmousemove = function(evt) {
if (moveable) {
var evt = evt||window.event;
msgObj.style.left = evt.clientX - posx + "px";
msgObj.style.top = evt.clientY - posy + "px";
}
change();
};
document.onmouseup = function () {
if (moveable) {
document.onmousemove = MouseMoveEvent;
document.onmouseup = MouseUpEvent;
moveable = false;
posx = 0;
posy = 0;
}
};
}
var v=1;
var a=0.9;
var h=document.documentElement.clientHeight;
function scroll(){
var timer=setInterval(function(){
v +=a;
var top=(parseInt(msgObj.style.top)||0);
if(top+v>h-70){
if(v<2)clearInterval(timer);
msgObj.style.top=h-70+"px";
v=-v*0.5;
}else{
msgObj.style.top=top+v+"px";
}
change();
},10);
};
$(document).keyup(function(e){
var e = e || window.event ;
if(e.which == 13){
scroll();
}
})
var x = 4 ;
var y = 4 ;
function newpro(){
var Height = document.documentElement.clientHeight ;
var Width = document.documentElement.clientWidth ;
var newobj = document.createElement('div');
newobj.setAttribute('id','bigbox');
newobj.style.position = 'absolute';
newobj.style.left = 20 +"px";
newobj.style.top = 80 +"px";
newobj.style.height = Height/x +"px" ;
newobj.style.width = Width/y +"px" ;
newobj.style.borderWidth = 1+"px";
newobj.style.borderColor = "#ff6500";
newobj.style.borderStyle = 'solid' ;
newobj.innerHTML='<div id="minbox"></div>';
document.body.appendChild(newobj);
change();
}
function change(){
var minobj = document.getElementById('minbox');
minobj.style.position = 'absolute';
minobj.style.left = parseInt(msgObj.style.left)/x +"px";
minobj.style.top = parseInt(msgObj.style.top)/y +"px";
minobj.style.height = 20 +"px" ;
minobj.style.width = 30 +"px" ;
minobj.style.background = "#F06";
}
window.onload = function(){
newpro();
}
</script>
</body>
</html>
希望本文所述對(duì)大家的jQuery程序設(shè)計(jì)有所幫助。
- jQuery實(shí)現(xiàn)的鼠標(biāo)拖動(dòng)浮層功能示例【拖動(dòng)div等任何標(biāo)簽】
- jquery div拖動(dòng)效果示例代碼
- jQuery拖動(dòng)div、移動(dòng)div、彈出層實(shí)現(xiàn)原理及示例
- jQuery實(shí)現(xiàn)單擊彈出Div層窗口效果(可關(guān)閉可拖動(dòng))
- jquery拖動(dòng)改變div大小
- 使用jQuery的easydrag插件實(shí)現(xiàn)可拖動(dòng)的DIV彈出框
- jquery實(shí)現(xiàn)可拖動(dòng)DIV自定義保存到數(shù)據(jù)的實(shí)例
- jQuery實(shí)現(xiàn)鼠標(biāo)拖動(dòng)div改變位置、大小的實(shí)踐
相關(guān)文章
jQuery選擇器源碼解讀(七):elementMatcher函數(shù)
這篇文章主要介紹了jQuery選擇器源碼解讀(七):elementMatcher函數(shù),本文講解了源碼、功能、參數(shù)、返回函數(shù) 等內(nèi)容,需要的朋友可以參考下2015-03-03淺析jQuery的鏈?zhǔn)秸{(diào)用之each函數(shù)
如果對(duì)于jquery的$()包裝器函數(shù)還不是很清楚,請(qǐng)先參閱我的上一篇日志:淺析jQuery的鏈?zhǔn)秸{(diào)用2010-12-12淺談jQuery的bind和unbind事件(綁定和解綁事件)
下面小編就為大家?guī)硪黄獪\談jQuery的bind和unbind事件(綁定和解綁事件)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-03-03jQuery刪除當(dāng)前節(jié)點(diǎn)元素
本文給大家分享一段代碼給大家介紹jquery刪除當(dāng)前節(jié)點(diǎn)元素的方法,代碼簡單易懂,非常不錯(cuò),需要的朋友參考下吧2016-12-12jquery實(shí)現(xiàn)手機(jī)號(hào)碼選號(hào)的方法
這篇文章主要介紹了jquery實(shí)現(xiàn)手機(jī)號(hào)碼選號(hào)的方法,涉及jquery針對(duì)手機(jī)號(hào)碼的分析與篩選技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-07-07JQuery設(shè)置獲取下拉菜單某個(gè)選項(xiàng)的值(比較全)
這篇文章主要介紹了JQuery如何設(shè)置獲取下拉菜單某個(gè)選項(xiàng)的值(比較全),需要的朋友可以參考下2014-08-08ASP.NET jQuery 實(shí)例4(復(fù)制TextBox的文本到本地剪貼板上)
在這節(jié),我們將看到如何把多行文本框的內(nèi)容復(fù)制到剪貼板上。注意:jQuery clipboard plugin 只支持IE2012-01-01