随笔-86  评论-767  文章-3  trackbacks-3

var offsetx = -120;
var offsety = -100;
ns4 = (document.layers)? true:false
ie4 = (document.all)? true:false

if (ie4) {
 if (navigator.userAgent.indexOf('MSIE 5')>0) {
  ie5 = true;
 } else {
  ie5 = false; }
} else {
 ie5 = false;
}

var x = 0;
var y = 0;
var para = 0;
var sw = 0;
var cnt = 0;
var dir = 1;
var tr=1;
if ( (ns4) || (ie4) ) {
 if (ns4) over = document.overDiv
 if (ie4) over = overDiv.style
 document.onmousemove = mouseMove
 if (ns4) document.captureEvents(Event.MOUSEMOVE)
}
function hide() {
 if ( cnt >= 1 ) { sw = 0 };
 if ( (ns4) || (ie4) ) {
  if ( sw == 0 ) {
   para = 0;
   hideObject(over);
  } else {
   cnt++;
  }
 }
}

function show(txt) {
 layerWrite(txt); 
 disp();
}
function layerWrite(txt) {
        if (ns4) {
                var lyr = document.overDiv.document
                lyr.write(txt)
                lyr.close()
        }
        else if (ie4) document.all["overDiv"].innerHTML = txt
  if (tr) {  }
}
function disp() {
 if ( (ns4) || (ie4) ) {
  if (para == 0)  {// Right   
    moveTo(over,x+offsetx,y+offsety);
   }   
   showObject(over);
   para = 1;
  }
 }

function mouseMove(e) {
 if (ns4) {x=e.pageX; y=e.pageY;}
 if (ie4) {x=event.x; y=event.y;}
 if (ie5) {x=event.x+document.body.scrollLeft; y=event.y+document.body.scrollTop;}
 if (para) {  
   moveTo(over,x+offsetx,y+offsety);
  }
 }
function cClick() {
 hideObject(over);
 sw=0;
}

 

// Make an object visible
function showObject(obj) {
        if (ns4) obj.visibility = "show"
        else if (ie4) obj.visibility = "visible"
}

// Hides an object
function hideObject(obj) {
        if (ns4) obj.visibility = "hide"
        else if (ie4) obj.visibility = "hidden"
}

// Move a layer
function moveTo(obj,xL,yL) {
        obj.left = xL
        obj.top = yL
}

另外,在要显示的页面中适当位置添加:
            <DIV id=overDiv style="POSITION: absolute; Z-INDEX: 1"></DIV>
            <SCRIPT language=javascript src="xxx.js"></SCRIPT>

示例地址:http://www.xmeteo.xm.fj.cn/fjcity.asp

posted on 2005-01-26 10:39 eamoi 阅读(4107) 评论(1)  编辑  收藏 所属分类: JS/VBS/HTML

评论:
# re: 浮动层显示JS代码 2011-11-08 19:11 | yfdyygydx
var offsetx = -120;
var offsety = -100;
ns4 = (document.layers)? true:false
ie4 = (document.all)? true:false

if (ie4) {
if (navigator.userAgent.indexOf('MSIE 5')>0) {
ie5 = true;
} else {
ie5 = false; }
} else {
ie5 = false;
}

var x = 0;
var y = 0;
var para = 0;
var sw = 0;
var cnt = 0;
var dir = 1;
var tr=1;
if ( (ns4) || (ie4) ) {
if (ns4) over = document.overDiv
if (ie4) over = overDiv.style
document.onmousemove = mouseMove
if (ns4) document.captureEvents(Event.MOUSEMOVE)
}
function hide() {
if ( cnt >= 1 ) { sw = 0 };
if ( (ns4) || (ie4) ) {
if ( sw == 0 ) {
para = 0;
hideObject(over);
} else {
cnt++;
}
}
}

function show(txt) {
layerWrite(txt);
disp();
}
function layerWrite(txt) {
if (ns4) {
var lyr = document.overDiv.document
lyr.write(txt)
lyr.close()
}
else if (ie4) document.all["overDiv"].innerHTML = txt
if (tr) { }
}
function disp() {
if ( (ns4) || (ie4) ) {
if (para == 0) {// Right
moveTo(over,x+offsetx,y+offsety);
}
showObject(over);
para = 1;
}
}

function mouseMove(e) {
if (ns4) {x=e.pageX; y=e.pageY;}
if (ie4) {x=event.x; y=event.y;}
if (ie5) {x=event.x+document.body.scrollLeft; y=event.y+document.body.scrollTop;}
if (para) {
moveTo(over,x+offsetx,y+offsety);
}
}
function cClick() {
hideObject(over);
sw=0;
}



// Make an object visible
function showObject(obj) {
if (ns4) obj.visibility = "show"
else if (ie4) obj.visibility = "visible"
}

// Hides an object
function hideObject(obj) {
if (ns4) obj.visibility = "hide"
else if (ie4) obj.visibility = "hidden"
}

// Move a layer
function moveTo(obj,xL,yL) {
obj.left = xL
obj.top = yL
}

  回复  更多评论
  

只有注册用户登录后才能发表评论。


网站导航: