Javascript制作浮动的工具条

该程序是我从别人的网站上分析出来的!由于对方的网站使用了框架,而且又取消了鼠标的右键功能,因此费了好长时间!
当你浏览该页时,工具条始终浮在左上角,你若不喜欢,可以自己调节摆放位置!若想多页使用该代码,可以把JSP程序部分写成JS的文件,然后再通过调用来实现,有不明白的地方,欢迎各位与我交流!

  1<html>
  2<head>
  3<title></title>
  4<meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>
  5<style type="text/css">   
  6.wdBlack{ font-size:9pt; line-height:11pt; font-family:宋体; color:black }   
  7.wdGray{ font-size:9pt; line-height:11pt; font-family:宋体; color:#CCCCCC }   
  8.wdBlue{ font-size:9pt; line-height:11pt; font-family:宋体; color:#2F8BDF }   
  9.wdRed{ font-size:9pt; line-height:11pt; font-family:宋体; color:red }   
 10.wdWhite{ font-size:9pt; line-height:11pt; font-family:宋体; color:white }   
 11.moveme{cursor: move;}   
 12.handle{cursor: move;}   
 13.coolBar{background: #fffffc;border-top: 1px solid buttonhighlight; border-left: 1px solid buttonhighlight; border-bottom: 1px solid buttonshadow; border-right: 1px solid buttonshadow; padding: 2px; font: menu;}   
 14.coolButton{font-size:9pt;border: 1px solid buttonface; padding: 1px; text-align: center; cursor: hand;color:#555555}   
 15.coolButton IMG {filter: gray();} div{ font-size:9pt; line-height:11pt; font-family:宋体; color:black }   
 16Text{ font-size:9pt; line-height:11pt; font-family:宋体; color:black }   
 17INPUT{ font-size:9pt; line-height:11pt; font-family:宋体; color:black }   
 18table{ font-size:9pt; line-height:11pt; font-family:宋体; color:black }   
 19body{ font-size:9pt; line-height:11pt; font-family:宋体; color:black }   
 20form{ font-size:9pt; line-height:11pt; font-family:宋体; color:black }   
 21  
 22A:link{ font-size:9pt; font-family:宋体; text-decoration: none; color:#2F8BDF }   
 23A:visited{ font-size:9pt; font-family:宋体; text-decoration: none; color:#2F8BDF }   
 24A:hover{ font-size:9pt; font-family:宋体; text-decoration: underline; color:#FF0000 }   
 25</style>
 26<script language="javascript">   
 27var dragobject = null;   
 28var tx;   
 29var ty;   
 30document.onmouseover = doOver;   
 31document.onmouseout = doOut;   
 32document.onmousedown = doDown;   
 33document.onmouseup = doUp;   
 34document.onmousedown=initDown;   
 35document.onmouseup=initUp;   
 36document.onmousemove=initMove;   
 37function stat(){   
 38var a = pageYOffset;   
 39document.bar.top = a;   
 40setTimeout('stat()',2);   
 41}   
 42function fix(){   
 43nome=navigator.appName   
 44if(nome=='Netscape') stat();   
 45else{   
 46var a=document.body.scrollTop;   
 47var b=document.body.scrollLeft;   
 48bar.style.top = a;   
 49bar.style.left = b;   
 50}   
 51}   
 52function getReal(el) {   
 53temp = el;   
 54while ((temp != null) && (temp.tagName != "BODY")) {   
 55if ((temp.className == "moveme") || (temp.className == "handle")){   
 56el = temp;   
 57return el;   
 58}   
 59temp = temp.parentElement;   
 60}   
 61return el;   
 62}   
 63function moveme_onmousedown() {   
 64el = getReal(window.event.srcElement)   
 65if (el.className == "moveme") {   
 66dragobject = el;   
 67ty = (window.event.clientY - dragobject.style.pixelTop);   
 68tx = (window.event.clientX - dragobject.style.pixelLeft);   
 69window.event.returnValue = false;   
 70window.event.cancelBubble = true;   
 71}else if (el.className == "handle") {   
 72tmp = el.getAttribute("for");   
 73if (tmp != null) {   
 74el = eval(tmp);   
 75dragobject = el;   
 76ty = (window.event.clientY - dragobject.style.pixelTop);   
 77tx = (window.event.clientX - dragobject.style.pixelLeft);   
 78window.event.returnValue = false;   
 79window.event.cancelBubble = true;   
 80} else {   
 81dragobject = null;   
 82}   
 83}else {   
 84dragobject = null;   
 85}   
 86}   
 87function moveme_onmouseup() {   
 88if(dragobject) {   
 89dragobject = null;   
 90}   
 91}   
 92function moveme_onmousemove() {   
 93if (dragobject) {   
 94if(window.event.clientX >= 0) {   
 95dragobject.style.left = window.event.clientX - tx;   
 96dragobject.style.top = window.event.clientY - ty;   
 97}   
 98window.event.returnValue = false;   
 99window.event.cancelBubble = true;   
100}   
101}   
102if (document.all) {   
103document.onmousedown = moveme_onmousedown;   
104document.onmouseup = moveme_onmouseup;   
105document.onmousemove = moveme_onmousemove;   
106}   
107function doOver() {   
108var toEl = getReal(window.event.toElement, "className", "coolButton");   
109var fromEl = getReal(window.event.fromElement, "className", "coolButton");   
110if (toEl == fromEl) return;   
111var el = toEl;   
112var cDisabled = el.cDisabled;   
113cDisabled = (cDisabled != null);   
114if (el.className == "coolButton")   
115el.onselectstart = new Function("return false");   
116if ((el.className == "coolButton") && !cDisabled) {   
117makeRaised(el);   
118makeGray(el,false);   
119}   
120}   
121function doOut() {   
122var toEl = getReal(window.event.toElement, "className", "coolButton");   
123var fromEl = getReal(window.event.fromElement, "className", "coolButton");   
124if (toEl == fromEl) return;   
125var el = fromEl;   
126var cDisabled = el.cDisabled;   
127cDisabled = (cDisabled != null);   
128var cToggle = el.cToggle;   
129toggle_disabled = (cToggle != null);   
130if (cToggle && el.value) {   
131makePressed(el);   
132makeGray(el,true);   
133}   
134else if ((el.className == "coolButton") && !cDisabled) {   
135makeFlat(el);   
136makeGray(el,true);   
137}   
138}   
139function doDown() {   
140el = getReal(window.event.srcElement, "className", "coolButton");   
141var cDisabled = el.cDisabled;   
142cDisabled = (cDisabled != null);   
143if ((el.className == "coolButton") && !cDisabled) {   
144makePressed(el)   
145}   
146}   
147function doUp() {   
148el = getReal(window.event.srcElement, "className", "coolButton");   
149var cDisabled = el.cDisabled;   
150cDisabled = (cDisabled != null);   
151if ((el.className == "coolButton") && !cDisabled) {   
152makeRaised(el);   
153}   
154}   
155function getReal(el, type, value) {   
156temp = el;   
157while ((temp != null) && (temp.tagName != "BODY")) {   
158if (eval("temp." + type) == value) {   
159el = temp;   
160return el;   
161}   
162temp = temp.parentElement;   
163}   
164return el;   
165}   
166function findChildren(el, type, value) {   
167var children = el.children;   
168var tmp = new Array();   
169var j=0;   
170for (var i=0; i<children.length; i++) {   
171if (eval("children[i]." + type + "=="" + value + """)) {   
172tmp[tmp.length] = children[i];   
173}   
174tmp = tmp.concat(findChildren(children[i], type, value));   
175}   
176return tmp;   
177}   
178function disable(el) {   
179if (document.readyState != "complete") {   
180window.setTimeout("disable(" + el.id + ")", 100);   
181return;   
182}   
183var cDisabled = el.cDisabled;   
184cDisabled = (cDisabled != null);   
185if (!cDisabled) {   
186el.cDisabled = true;   
187el.innerHTML = '<span style="background: buttonshadow; width: 100%; height: 100%; text-align: center;border:1px">' +   
188'<span style="filter:Mask(Color=buttonface) DropShadow(Color=buttonhighlight, OffX=1, OffY=1, Positive=0); height: 100%; width: 100%%; text-align: center;border:1px">' +   
189el.innerHTML +   
190'</span>' +   
191'</span>';   
192if (el.onclick != null) {   
193el.cDisabled_onclick = el.onclick;   
194el.onclick = null;   
195}   
196}   
197}   
198function enable(el) {   
199var cDisabled = el.cDisabled;   
200cDisabled = (cDisabled != null);   
201if (cDisabled) {   
202el.cDisabled = null;   
203el.innerHTML = el.children[0].children[0].innerHTML;   
204if (el.cDisabled_onclick != null) {   
205el.onclick = el.cDisabled_onclick;   
206el.cDisabled_onclick = null;   
207}   
208}   
209}   
210function addToggle(el) {   
211var cDisabled = el.cDisabled;   
212cDisabled = (cDisabled != null);   
213var cToggle = el.cToggle;   
214cToggle = (cToggle != null);   
215if (!cToggle && !cDisabled) {   
216el.cToggle = true;   
217if (el.value == null)   
218el.value = 0;   
219if (el.onclick != null)   
220el.cToggle_onclick = el.onclick;   
221else   
222el.cToggle_onclick = "";   
223el.onclick = new Function("toggle(" + el.id +"); " + el.id + ".cToggle_onclick();");   
224}   
225}   
226function removeToggle(el) {   
227var cDisabled = el.cDisabled;   
228cDisabled = (cDisabled != null);   
229var cToggle = el.cToggle;   
230cToggle = (cToggle != null);   
231if (cToggle && !cDisabled) {   
232el.cToggle = null;   
233if (el.value) {   
234toggle(el);   
235}   
236makeFlat(el);   
237if (el.cToggle_onclick != null) {   
238el.onclick = el.cToggle_onclick;   
239el.cToggle_onclick = null;   
240}   
241}   
242}   
243function toggle(el) {   
244el.value = !el.value;   
245if (el.value)   
246el.style.background = "URL()";   
247else   
248el.style.backgroundImage = "";   
249}   
250function makeFlat(el) {   
251with (el.style) {   
252background = "";   
253border = "1px solid buttonface";   
254padding = "1px";   
255}   
256}   
257function maeRaised(el) {   
258with (el.style) {   
259borderLeft = "1px solid #2F8BDF";   
260borderRight = "1px solid #2F8BDF";   
261borderTop = "1px solid #2F8BDF";   
262borderBottom = "1px solid #2F8BDF";   
263padding = "1px";   
264}   
265}   
266function makePressed(el) {   
267with (el.style) {   
268borderLeft = "1px solid buttonhighlight";   
269borderRight = "1px solid buttonshadow";   
270borderTop = "1px solid buttonhighlight";   
271borderBottom = "1px solid buttonshadow";   
272  
273paddingTop = "2px";   
274paddingLeft = "2px";   
275paddingBottom = "0px";   
276paddingRight = "0px";   
277}   
278}   
279function makeGray(el,b) {   
280var filtval;   
281if (b)   
282filtval = "gray()";   
283else   
284filtval = "";   
285var imgs = findChildren(el, "tagName", "IMG");   
286for (var i=0; i<imgs.length; i++) {   
287imgs[i].style.filter = filtval;   
288}   
289}   
290function load(ws) {   
291parent.location.href=ws;   
292}   
293function initDown() {   
294doDown();   
295moveme_onmousedown();   
296}   
297function initUp() {   
298doUp();   
299moveme_onmouseup();   
300}   
301function initMove() {   
302moveme_onmousemove();   
303}   
304</script>
305</head>
306<body onload="fix()" onresize="fix()" onscroll="fix()">
307<span id="bar" style="position:absolute;left:0px;top:0px;width:500px; height:1px; z-index:9">
308<table class="coolBar" id="toolbar1" width="100%">
309<tr>
310<td class="coolButton" onclick="javascript:self.location='http://www.85time.com/85time/'">网友论坛</td>
311<td class="coolButton" onclick="javascript:self.location='http://www.85time.com/engine.htm'">实用引擎</td>
312<td class="coolButton" onclick="javascript:self.location='http://www.85time.com/opus/opus.htm'">推荐作品</td>
313<td class="coolButton" onclick="javascript:self.location='http://www.85time.com/gb/'">留言板</td>
314<td class="coolButton" onclick="javascript:self.location='http://www.85time.com/chat/'">聊天室</td>
315</tr>
316</table>
317</span>
318</body>
319</html>
Published At
Categories with 网页设计
Tagged with
comments powered by Disqus