function Tag(){
this.id;
this.name;
this.style;
this.src;
this.title;
this.pX;
this.pY;
this.pW;
this.pH;
this.content;
this.create = function(){
this.content = "<img src=\""+this.src+"\" id=\""+this.id+"\" name=\""+this.name+"\" style=\""+this.style+"\" title=\""+this.title+"\" onMouseDown=\"down(this);\" onMouseMove=\"moving(this,"+getPxValue(this.pX)+","+getPxValue(this.pY)+","+getPxValue(this.pW)+","+getPxValue(this.pH)+");\" onMouseUp=\"up(this);\"/>";
return this.content;
}
}
function DragObj() {
var flag=0;//0:no,1:yes
var x=0;
var y=0;
}
var dEvt = new DragObj();
function down(obj) {
//拖拽开始
dEvt.flag = 1;
//记录点击时鼠标坐标
dEvt.x = event.x;
dEvt.y = event.y;
obj.setCapture(); //得到鼠标
}
function moving(obj,pX,pY,pW,pH) {
if(event.button==1) {
if (dEvt.flag==1) {
//更新控件位置:新位置=鼠标位置-控件宽(高)/2
var left = event.x-pX-obj.style.pixelWidth/2;
var top = event.y-pY-obj.style.pixelHeight/2;
var width = getPxValue(obj.style.width);
var height = getPxValue(obj.style.height);
if(left>=0&&(parseInt(left)+parseInt(width))<=(parseInt(pW))){
obj.style.left = left;
}
if(top>=0&&(parseInt(top)+parseInt(height))<=(parseInt(pH))){
obj.style.top = top;
}
}
}
}
function up(obj) {
dEvt.flag=0;
obj.releaseCapture();
}
function getPxValue(px){
var str = px.substring(0,px.length-2);
return str;
}
js创建动态标签
最新推荐文章于 2024-07-23 20:55:14 发布