Javascript可移动窗口的设计
<html>
<head><title>js可移动窗口的设计</title>
<script language="javascript">
var x0=0,y0=0,x1=0,y1=0;//初始化全局变量
var offx=6,offy=6;
var moveable=false;
var hover='orange';//color;
var index=10000;//z-index;
//关闭窗口
function closeWin(id)
{
document.getElementById(id).style.display=document.getElementById(id).style.display=="none"?"block":"none";
}
//点击鼠标右键准备开始拖动窗口
function startDrag(obj)
{
if(event.button==1) {
obj.setCapture();//设置鼠标捕获的对象为当前对象,简单说就是获得鼠标拖动
var win = obj;
x0 = event.clientX;//记录点击鼠标右键的鼠标坐标
y0 = event.clientY;
x1 = parseInt(win.style.left);//记录框架的初始位置——鼠标坐标
y1 = parseInt(win.style.top);
normal = obj.style.backgroundColor;
win.style.backgroundColor = hover;
moveable = true;
}
}
//开始拖动窗口
function drag(obj)
{
if(moveable)
{
var win = obj;
win.style.left = x1 + event.clientX - x0;//进行坐标运算并控制样式的left与top属性
win.style.top = y1 + event.clientY - y0;
document.getElementById("xy").innerHTML = (x1 + event.clientX - x0)+","+(y1 + event.clientY - y0);//显示鼠标的坐标
}
}
//停止拖动
function stopDrag(obj)
{
var win = obj;
win.style.borderColor = normal;
obj.style.backgroundColor = normal;
obj.releaseCapture();//从当前对象中释放鼠标捕获的对象,简单说就是鼠标的释放
moveable = false;
}
</script>
<style>
.helpdiv {
display: block;
border: 1px dashed #749F4d;
background-color: #F0FAEB;
width: 500px;
padding: 5px;
position: absolute;
&n
相关文档:
to make a note that I love JavaScript. This article is only meant for some fun, and for us to be aware of some its short-comings.
1. The Name. JavaScript is NOT Java
We'll start with a fun jab at the name choice. While it was originally called Mocha, and then LiveScript, it was later changed to J ......
<script language="JavaScript">
<!--
//图片按比例缩放
var flag=false;
function DrawImage(ImgD,iwidth,iheight){
//参数(图片,允许的宽度,允许的高度)
var image=new Image();
image.src=ImgD.src; ......
这句话是:prototype中定义的是对象实例要访问的属性或方法的一个替补。
举例说明一下:
//1)定义了一个对象:
function A()
{
//给对象定义一个属性
this.f1="this is f1";
}
//2)我们可以这样使用对象:
var a = new A();
alert(a.f1)//弹出消息:this is f1
//3)我们可以扩展对象:
A.prot ......
先给出基本的HTML文件:
<ul>
<li id="m01"></li>
<li id="m01"></li>
<li id="m01"></li>
</ul>
<div>
<div id="C01"> </div>
<div id="C02">&n ......
一、什么是事件冒泡
在一个对象上触发某类事件(比如单击onclick事件),如果此对象定义了此事件的处理程序,那么此事件就会调用这个处理程序,如果没有定义此事 件处理程序或者事件返回true,那么这个事件会向这个对象的父级对象传播,从里到外,直 ......