码迷,mamicode.com
首页 > Web开发 > 详细

外贸建站之导航栏NAV菜单监听JS处理代码

时间:2019-04-07 19:20:07      阅读:221      评论:0      收藏:0      [点我收藏+]

标签:closed   tac   close   pre   settime   nbsp   net   amp   tag   

外贸建站之导航栏NAV菜单监听JS处理代码

 

 1 var persistclose=1 //set to 0 or 1. 1 means once the bar is manually closed, it will remain closed for browser session
 2 var startX = 30 //set x offset of bar in pixels
 3 var startY = 5 //set y offset of bar in pixels
 4 var verticalpos="fromtop" //enter "fromtop" or "frombottom"
 5 
 6 function iecompattest(){
 7 return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
 8 }
 9 
10 function get_cookie(Name) {
11 var search = Name + "="
12 var returnvalue = "";
13 if (document.cookie.length > 0) {
14 offset = document.cookie.indexOf(search)
15 if (offset != -1) {
16 offset += search.length
17 end = document.cookie.indexOf(";", offset);
18 if (end == -1) end = document.cookie.length;
19 returnvalue=unescape(document.cookie.substring(offset, end))
20 }
21 }
22 return returnvalue;
23 }
24 
25 function closebar(){
26 if (persistclose)
27 document.cookie="remainclosed=1"
28 document.getElementById("topbar").style.visibility="hidden"
29 }
30 
31 function staticbar(){
32         barheight=document.getElementById("topbar").offsetHeight
33         var ns = (navigator.appName.indexOf("Netscape") != -1) || window.opera;
34         var d = document;
35         function ml(id){
36                 var el=d.getElementById(id);
37                 if (!persistclose || persistclose && get_cookie("remainclosed")=="")
38                 el.style.visibility="visible"
39                 if(d.layers)el.style=el;
40                 el.sP=function(x,y){this.style.right=x+"px";this.style.top=y+"px";};
41                 el.x = startX;
42                 if (verticalpos=="fromtop")
43                 el.y = startY;
44                 else{
45                 el.y = ns ? pageYOffset + innerHeight : iecompattest().scrollTop + iecompattest().clientHeight;
46                 el.y -= startY;
47                 }
48                 return el;
49         }
50         window.stayTopLeft=function(){
51                 if (verticalpos=="fromtop"){
52                 var pY = ns ? pageYOffset : iecompattest().scrollTop;
53                 ftlObj.y += (pY + startY - ftlObj.y)/8;
54                 }
55                 else{
56                 var pY = ns ? pageYOffset + innerHeight - barheight: iecompattest().scrollTop + iecompattest().clientHeight - barheight;
57                 ftlObj.y += (pY - startY - ftlObj.y)/8;
58                 }
59                 ftlObj.sP(ftlObj.x, ftlObj.y);
60                 setTimeout("stayTopLeft()", 10);
61         }
62         ftlObj = ml("topbar");
63  stayTopLeft();
64 }
65 
66 if (window.addEventListener)
67 window.addEventListener("load", staticbar, false)
68 else if (window.attachEvent)
69 window.attachEvent("onload", staticbar)
70 else if (document.getElementById)
71 window.onload=staticbar

改代码是非常成熟的组件了,我们在开发Renault CAN Clip项目中有用到,使用也非常简单,这里发出来给大家参考。

外贸建站之导航栏NAV菜单监听JS处理代码

标签:closed   tac   close   pre   settime   nbsp   net   amp   tag   

原文地址:https://www.cnblogs.com/aid12580/p/10666531.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!