XP folding menu & imitation QQ2006 menu_javascript skills
Features:
Better appearance: added icon on menu title.
Better actions: Implemented menu sliding in and sliding out effects.
Easier to use: Many comments have been added for easy use.
Of course there are still some undiscovered problems. I hope you can give me some advice:)
Implementing a foldable dynamically changing the value of style.height. This is not very professional:) But it looks very similar!
100% original winXP collapsible menu appearance! If it's different, please tell me and I'll change it.
(qq2006 still has some jitters when clicking.)
Look at the picture first. The latest addition The appearance of qq2006
Test webpage address: navbar.htm
Detailed URL: http://lxbzj.com/showartical.asp?N_id=156
Download: http://lxbzj.com/upload/200604/menu.zip
The new version is still in production. . . (The updated js is on layer 19)
Here is the js modified on 2006-04-13
- It is no longer necessary to add onclick and onkeypress to each This way, the web page and js are further separated
-Define a menu class responsible for adding events to each menu
-Modify onkeypress
-Add interval processing
-Add a retracting acceleration (but not very obvious)
-Added Navbar object, so that only one menu can be opened in a group
-New js is constantly being updated. . .
- Code in navbar.js:
// JavaScript Document
/*==================================== =====
* File name: navbar.js
* Encoding: Utf-8
* Function: javaScript to implement menu folding
* Author: Lei Xiaobao
* Version: 2.3
* Time: 2006-03-07
============================== =============*/
//==========================Define menu class=== ===============;
function Menu(head,child,dir,speed,init_state,ext_on,ext_off)
{
this.head = document.getElementById (head);//Menu header
this.body = document.getElementById(child);//Menu body
this.direction = dir;//Menu retracting direction
this.speed = speed ;//Speed
this.ext_on = ext_on;//Extended menu expansion call
this.ext_off = ext_off;//Extended menu collapse call
this.init_state = init_state;//Initial setting of menu State true/false
this.a = 10;//Acceleration
//Private variable;
this._interval = false;
this._last_state = false;
this._size = false;
this._temp = false;
this._js = false;
this._div = false;
this._parent = false;
this._parent_control = false;
var self = this;
var temp = new Array(null,null);//temp[0] is used for _off(), temp[1] is used for _on()
//==============================Method================ =============
//Click event processing
this.click = function(e)
{
if (self._parent_control)
{ if (self._last_state = = false)
🎜> 🎜> 🎜> this.head.onkeypress = function(e)
{
e||(e=window.event);
if (!(e.keyCode ==32 || e.keyCode == 0) )return;
//alert(':)');
for(var i=0;i
if (this.body.childNodes[i].nodeType==1)
{
this._div=this.body.childNodes[i];
break;
}
}
if (parseInt(this.body.style.height))//this.body.style.getPropertyCSSValue('height')this.body.currentStyle.height
{
this._size = parseInt(this.body.style.height);
}
else
{
this._size = this._div.offsetHeight;
}
switch (this.init_state)
{
case true:
if (this.body.style.display == 'none')
{
//this._last_state = false;
this._on();
}
else
{
this._last_state = true;
}
break;
default://case false:
if (this.body.style.display !='none')
{
this._last_state = true;
this._off();
}
break;
}
}
//展开菜单
this._on = function()
{
if (self._last_state == false)
{
self._last_state = true;
self.body.style.display="";
temp[1] = self.a?2*parseInt(Math.sqrt(self.a*self._size)) 1:self._size/5;
if (isNaN(parseInt(self.body.style.height)))self.body.style.height="0px";
if (self.ext_on)
{
self.ext_on(self.head,self.body)
}
self._interval = Interval.set(self._action_on,speed);
}
//setTimeout('slowon("' self.body.id '")',5)
}
//收起菜单
this._off = function()
{
if (self._last_state == true)
{
self._last_state = false;
//if (temp[0] == null)
//{
temp[0]=self.a?2*parseInt(Math.sqrt(self.a*self._size)) 1:self._size/5;;
//}
if(isNaN(parseInt(self.body.style.height)))self.body.style.height = self._size 'px';
if (self.ext_off)
{
self.ext_off(self.head,self.body)
}
self._interval = Interval.set(self._action_off,this.speed);
}
}
//以下处理滑动
this._action_on = function()
{
if (parseInt(self.body.style.height) temp[1]>self._size)
{
self.body.style.height = self._size 'px';
Interval.clear(self._interval);
}
else
{
self.body.style.height = parseInt(self.body.style.height) temp[1] 'px';
temp[1] =self.a;
}
}
this._action_off = function()
{
if(parseInt(self.body.style.height)-temp[0]<0)
{
Interval.clear(self._interval);
self.body.style.display = "none";
}
else
{
self.body.style.height = parseInt(self.body.style.height)-temp[0] 'px';
temp[0]-=self.a ;
}
}
}
//End of meanu class
//====================Definition Navbar class, used to manage a set of menu collections ================================
function navbar(dir,a ,speed,ext_on,ext_off)
{
this.open_only_one = true;//Whether only one menu of this group is open at any time, true/false
this.dir = dir;//menu group public direction. Since it is a group of menus, they should have the same direction, right?
this.a =a;//menu Public acceleration
this.speed =speed;//Public speed
this.ext_on = ext_on;//Public extension open function call
this.ext_off = ext_off;//Public extension collapse function call
this.menu_item = new Array();//menu group
this._openning;//If only one menu is allowed to be opened, this will record the currently opened one Menu
this.open_all = function()//
{
};
this.add = function (head,body)//Function to add menu
{
var temp = new Menu(head,body,this.dir,this.speed,this.ext_on,this.ext_off);
this.menu_item.push(temp);
};
this.init = function ()//Navbar’s initialization function must be called after add is completed.
{
if(this.open_only_one == true)
A menu is open
if (this.menu_item.length>0)
{
with(this.menu_item[0])
🎜> init_state = true;
_parent = this;//Set the father of the menu as this Navbar
_parent_control = true;//Set the parent to control the menu
init();
} }
This._openning = this.menu_item[0] ;
through > 🎜> init();
}
else
{//If open_only_one == false then only initialize the menu
for(var i = 0;i
this.menu_item.init();
;
//Additional parent control function
this._control = function(child)
{
var self =child;
Interval.clear(self._interval);
if (self._last_state == false)
._openning._off();
self._parent. }
else
{
//self._off( );
return false; ====================interval processing============================ =
//Note: _stack only has 20 items
//When expanding, an initial value of 1-n must be assigned
Interval=
{
length:20,
_action: new Array( length),
_stack : new Array(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19 ),
_interval : Array(length),
_timeout: new Array(length),
//for(var i=0;i<_action.length;i )stack.push(i); ,
set:function(action_function,speed,time_out)
{
time_out = time_out?time_out:15000;//The default interval timeout is 15000 seconds. If you do not need to set a timeout, then setTimeout below Then comment out the line; val._interval[p ]=setInterval('if(Interval._action[' p '])Interval._action[' p ']();',speed);//The repeated execution function here cannot be written as 'Interval._action[' p '] 'Because it is very likely that after Interval.clear, there will be another execution that has not been completed, so an error occurred
Interval._timeout[p] Interval.clear(' p ')', time_out); // This line sets the interval timeout, you can comment it out if you don’t need it;
; p])
🎜> Interval._action[p] = "";
Interval._stack.push(p);
}
}
}
//Interval processing ends

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

The shift from C/C to JavaScript requires adapting to dynamic typing, garbage collection and asynchronous programming. 1) C/C is a statically typed language that requires manual memory management, while JavaScript is dynamically typed and garbage collection is automatically processed. 2) C/C needs to be compiled into machine code, while JavaScript is an interpreted language. 3) JavaScript introduces concepts such as closures, prototype chains and Promise, which enhances flexibility and asynchronous programming capabilities.

The main uses of JavaScript in web development include client interaction, form verification and asynchronous communication. 1) Dynamic content update and user interaction through DOM operations; 2) Client verification is carried out before the user submits data to improve the user experience; 3) Refreshless communication with the server is achieved through AJAX technology.

JavaScript's application in the real world includes front-end and back-end development. 1) Display front-end applications by building a TODO list application, involving DOM operations and event processing. 2) Build RESTfulAPI through Node.js and Express to demonstrate back-end applications.

Understanding how JavaScript engine works internally is important to developers because it helps write more efficient code and understand performance bottlenecks and optimization strategies. 1) The engine's workflow includes three stages: parsing, compiling and execution; 2) During the execution process, the engine will perform dynamic optimization, such as inline cache and hidden classes; 3) Best practices include avoiding global variables, optimizing loops, using const and lets, and avoiding excessive use of closures.

Python and JavaScript have their own advantages and disadvantages in terms of community, libraries and resources. 1) The Python community is friendly and suitable for beginners, but the front-end development resources are not as rich as JavaScript. 2) Python is powerful in data science and machine learning libraries, while JavaScript is better in front-end development libraries and frameworks. 3) Both have rich learning resources, but Python is suitable for starting with official documents, while JavaScript is better with MDNWebDocs. The choice should be based on project needs and personal interests.

Both Python and JavaScript's choices in development environments are important. 1) Python's development environment includes PyCharm, JupyterNotebook and Anaconda, which are suitable for data science and rapid prototyping. 2) The development environment of JavaScript includes Node.js, VSCode and Webpack, which are suitable for front-end and back-end development. Choosing the right tools according to project needs can improve development efficiency and project success rate.

C and C play a vital role in the JavaScript engine, mainly used to implement interpreters and JIT compilers. 1) C is used to parse JavaScript source code and generate an abstract syntax tree. 2) C is responsible for generating and executing bytecode. 3) C implements the JIT compiler, optimizes and compiles hot-spot code at runtime, and significantly improves the execution efficiency of JavaScript.
