当前位置: 首页 > 图文教程 > 网络编程 > Javascript > 绝对精彩:在网页里做类似window右键的弹出式菜单

Javascript
JQuery Tips(3) 关于$()包装集内元素的改变
JavaScript 创建随机数和随机图片
javascript document.execCommand() 常用解析
firefox下对ajax的onreadystatechange的支持情况分析
Javascript attachEvent传递参数的办法
jQuery Attributes(属性)的使用(一、属性篇)
jquery自动完成插件(autocomplete)应用之PHP版
查询绑定数据岛的表格中的文本并修改显示方式的js代码
讨论javascript(一)工厂方式 js面象对象的定义方法
IE不支持option的display样式,只能使用remove和add
多浏览器兼容的获取元素和鼠标的位置的js代码
js checkbox全选并将获取值放到input里边
javascript 日期联动选择器 [其中的一些代码值得学习]
javascript实现的仿51job地址多项选择方式效果
jQuery 渐变下拉菜单
利用图片的 onerror 事件载入默认图片
js实现页面打印功能实例代码(附去页眉页脚功能代码)
JQuery读取XML文件数据并显示的实现代码
比较详细的关于javascript 解析json的代码
TextArea 控件的最大长度问题(js json)

Javascript 中的 绝对精彩:在网页里做类似window右键的弹出式菜单


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-10   浏览: 188 ::
收藏到网摘: n/a

做一个类似于window右键的弹出式菜单。

直接下载js文件和观看效果: http://202.114.98.14/~cityhunter/jscripts/jscripts.htm
代码如下: 

var obj;

function loadobj(o)
{
  obj=o;
}

function expand()
{
  var h=parseInt(obj.height);
  var w=parseInt(obj.width);
  var op=10;

  if( h<=170 )
  {
    if( w<60 )
      obj.style.width=w+6;

    obj.style.height=h+17;

    x=setTimeout('expand()', 25);
  }
  else
  {
    obj.style.width=60;
    obj.style.height=174;
    clearTimeout(x);
  }
}

var drag=0;
var move=0;
function Dblclick()
{
  if (event.button==0)
    {
      obj.style.visibility="visible";
      obj.style.left=window.event.x;
      obj.style.top =window.event.y;
      obj.style.width=0;
      obj.style.height=0;

      obj.filters.item(0).apply();
      obj.filters.item(0).transition = 25;
      obj.filters(0).play(0.5);

      expand();
    }
}

function MouseMove()
{
  if(move==1)
    {
      obj.style.cursor="move";
      obj.style.left=window.event.x-l;
      obj.style.top=window.event.y-t;
    }
}

function MouseDown()
{
  if(drag) 
    {
      l = window.event.x - parseInt(obj.style.left);
      t = window.event.y - parseInt(obj.style.top);
      obj.style.zIndex+=1;
      move=1;
    }
  else
    {
      document.body.style.cursor='default';
      obj.style.visibility='hidden';
    }
}

function MouseStop()
{
  window.event.returnValue=false;
}

function MouseUp()
{
  move=0;
  obj.style.cursor="hand";
}

document.ondblclick=Dblclick;
document.onmousedown=MouseDown;
document.onmousemove=MouseMove;
document.ondragstart=MouseStop;
document.onmouseup=MouseUp;