简单的javascript拖拽实例
简单的javascript拖拽实例----> 本人原创(244796562@qq.com)
<html>
<head>
<title>拖拽测试</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<div id="box" style="position:absolute;top:100px;left:200px;width:200px;height:200px;background-color:#C0C0C0;border:solid 1px #555555">
<div id="bar" title="可移动" style="cursor:pointer;background-color:#0099FF;border-bottom:solid 1px #555555" mce_style="cursor:pointer;background-color:#0099FF;border-bottom:solid 1px #555555">
<b>title:拖动条</b>
</div>
content:内容区
</div>
<mce:script type="text/javascript"><!--
function stopBubble(e) {//禁止冒泡事件
if (e && e.stopPropagation) {
e.stopPropagation();
} else {
window.event.cancelBubble = true;
}
}
function stopDefault(e) {//禁止默认行为
if (e && e.preventDefault) {
e.preventDefault();
} else {
window.event.returnValue = false;
}
return false;
}
function drag(box, bar) {//被拖拽的元素必须有top(px)和left(px)属性
var lastMouseX, lastMouseY;
if (!box.style.left || !box.style.top) {//如果真的没有top(px)和left(px)属性,加默认值
box.style.left = "10px";
box.style.top = "10px";
}
function getMousePos(e) {//获取鼠标坐标
e = e || window.event;
return {x: e.clientX, y: e.clientY};
}
bar.onmousedown = function(ed) {//初始化拖拽事件
stopBubble(ed);
stopDefault(ed);
var lastMousePos = getMousePos(ed);
lastMouseX = lastMousePos.x;
lastMouseY = lastMousePos.y;
window.top.document.onmousemove = function(em) {//注册移动事件
stopBubble(em);
stopDefault(em);
var currentMousePos = getMousePos(em);//当前鼠标位置
var currentMouseX = currentMousePos.x;
var currentMouseY = currentMousePos.y;
var boxLeft = parseInt(box.style.left);//拖动层的位置
var boxTop = parseInt(box.style.top);
box.style.left = boxLeft + currentMouseX - lastMouseX +
相关文档:
scrollHeight: 获取对象的滚动高度。
scrollLeft:设置或获取位于对象左边界和窗口中目前可见内容的最左端之间的距离
scrollTop:设置或获取位于对象最顶端和窗口中可见内容的最顶端之间的距离
scrollWidth:获取对象的滚动宽度
offsetHeight:获取对象相对于版面或由父坐标 offsetParent 属性指定的父坐标的高度
offsetL ......
黄色部分为date.js
<script type="text/javascript" src="/js/date.js"></script>
<input name="date" type="text" id="date" onBlur="checkDay(this)" style="width:160px;" /><INPUT class="button" style="WIDTH: 64px; HEIGHT: 24px" onClick="setday(this,date)"type="button" value="选择日期 ......
代码入下:
<script language="JavaScript">
function getMyName(){
var myName="<%=session.getAttribute("MYNAME")%>";
alert(myName);
}
</script>
JavaScript存session的值:
从理论上来说JavaScript在页面,而存session在服务器端..很难完成,但是你可 ......
在写读后感之前,先自我介绍一下,本人,男,24岁,未婚,资浅.NET程序员,在读此书之前已经能够熟练的利用JavaScript进行表单的一般验证(通过document.getElementById获取出文本框的值后再进行if...else...判断)。
刚刚拿到此书,心情好一番激动,沃~~~新华字典,长约26CM,宽约18CM,高约3.5 ......
近日收集上万行代码,整理一些出来。
//V8引擎的实现
function ToInteger( n ) {
n = Number( n );
var sign = ( n < 0 ) ? -1 : 1;
if ( n != n ) {
return 0;
}
if ( Math.abs( n ) == 0 || Math.abs( n ) == Number.POSITIVE_INFINITY ) {
......