最近一直在研究網頁特效,看到qq界面的折疊菜單,於是冒出個想法,自己寫一個類似的,上網查了一下,發現已經有不少類似的菜單效果,不管那麼多,先寫著再說吧.
以下是html結構:
id為a裡的便是你要加入的選單的標題與內容.
下面是javascript程式碼:
sx.activex.packmenu={
create:function(t) {
var a=document.createElement("div");
var _t=t;
a.style.height="300px";
a.style.width="150px";
a.style.border="1px red solid";
a.style.overflow="hidden";
for(var i=0;i
var b=document.createElement("div");;
h.style.backgroundColor="blue";
h.style.height= "10%";
b.style.padding="5px";
b.style.textAlign="center";
b.style.border="1px green solid";
h .innerHTML=t[i][0];
b.innerHTML=t[i][1];
b.style.overflow="hidden";
b.style.height="0px ";
b.style.display="none";
h.onclick=function(){
if(this.nextSibling.style.display=="none"){
this. nextSibling.style.height="1px";
this.nextSibling.style.display="block";
this.h=window.setInterval(function(t,t1){
return function() {
if(!t1) return;
//alert(t.nextSibling.offsetHeight);
if(parseInt(t.nextSibling.style.height)t.nextSibling.style.height=parseInt(t.nextSibling.style.height) 3 "%";
t1.style.height=parseInt (t1.style.height)-3 "%";
}
else{
t.nextSibling.style.height=100-_t.length*parseInt(a.all[0].style. height) "%";;
t1.style.display="none";
t1.style.height="0px";
window.clearInterval(t.h);
}
}
}(this,(function(){
for(var ii=0;ii
return a.all[ii];
}
})()),10);
}
else{
if(this!=this .parentNode.firstChild){
this.previousSibling.style.height="1px";
this.previousSibling.style.display="block";
}
else{
this. parentNode.lastChild.style.display="block";
this.parentNode.lastChild.style.height="1px";
}
this.h=window.setInterval(function(t,t1) {
return function(){
if(!t1) return;
if(parseInt(t.nextSibling.style.height)>3){
if(t!=t.parentNode. firstChild)
t.previousSibling.style.height=parseInt(t.previousSibling.style.height) 3 "%";
else
t.parentNode.lastChild.style.height=parseInt(t.parentNodeInt(t. .lastChild.style.height) 3 "%";
t1.style.height=parseInt(t1.style.height)-3 "%";
}
else{
if(t!=t.parentNode.firstChild)
t.previousSibling.style.height=100-_t.length*parseInt(a.all[0].style.height) "%";
else
t.parentNode.lastChild.style.height=100-_t.length*parseInt(a.all[0].style.height) "%";
t.nextSibling.style.display=" none";
t.nextSibling.style.height="0px";
window.clearInterval(t.h);
}
}
}(this,(function(){
for(var ii=0;ii
return a.all[ii] ;
}
})()),1);
}
}
a.appendChild(h);
a.appendChild(b);
a. all[1].style.display="block";
a.all[1].style.height=100-t.length*parseInt(a.all[0].style.height) "%";
}
return a;
}
}
入口參數t是你要傳遞的二維陣列,以一個標題加上內容為一個陣列項目的形式:
下面是呼叫程式碼:
<script> <BR>var a=sx.activex.packmenu.create([["asd","sadsadas"],["sd"," sadsaas"],["w","waedqwdq"],["e","efwefw"]]); <BR>//a.contentEditable=true; <BR>document.body.appendChild(a); <BR></script>
搞定,有興趣的朋友可以看下效果.

C 和JavaScript通過WebAssembly實現互操作性。 1)C 代碼編譯成WebAssembly模塊,引入到JavaScript環境中,增強計算能力。 2)在遊戲開發中,C 處理物理引擎和圖形渲染,JavaScript負責遊戲邏輯和用戶界面。

JavaScript在網站、移動應用、桌面應用和服務器端編程中均有廣泛應用。 1)在網站開發中,JavaScript與HTML、CSS一起操作DOM,實現動態效果,並支持如jQuery、React等框架。 2)通過ReactNative和Ionic,JavaScript用於開發跨平台移動應用。 3)Electron框架使JavaScript能構建桌面應用。 4)Node.js讓JavaScript在服務器端運行,支持高並發請求。

Python更適合數據科學和自動化,JavaScript更適合前端和全棧開發。 1.Python在數據科學和機器學習中表現出色,使用NumPy、Pandas等庫進行數據處理和建模。 2.Python在自動化和腳本編寫方面簡潔高效。 3.JavaScript在前端開發中不可或缺,用於構建動態網頁和單頁面應用。 4.JavaScript通過Node.js在後端開發中發揮作用,支持全棧開發。

C和C 在JavaScript引擎中扮演了至关重要的角色,主要用于实现解释器和JIT编译器。1)C 用于解析JavaScript源码并生成抽象语法树。2)C 负责生成和执行字节码。3)C 实现JIT编译器,在运行时优化和编译热点代码,显著提高JavaScript的执行效率。

JavaScript在現實世界中的應用包括前端和後端開發。 1)通過構建TODO列表應用展示前端應用,涉及DOM操作和事件處理。 2)通過Node.js和Express構建RESTfulAPI展示後端應用。

JavaScript在Web開發中的主要用途包括客戶端交互、表單驗證和異步通信。 1)通過DOM操作實現動態內容更新和用戶交互;2)在用戶提交數據前進行客戶端驗證,提高用戶體驗;3)通過AJAX技術實現與服務器的無刷新通信。

理解JavaScript引擎內部工作原理對開發者重要,因為它能幫助編寫更高效的代碼並理解性能瓶頸和優化策略。 1)引擎的工作流程包括解析、編譯和執行三個階段;2)執行過程中,引擎會進行動態優化,如內聯緩存和隱藏類;3)最佳實踐包括避免全局變量、優化循環、使用const和let,以及避免過度使用閉包。

Python更適合初學者,學習曲線平緩,語法簡潔;JavaScript適合前端開發,學習曲線較陡,語法靈活。 1.Python語法直觀,適用於數據科學和後端開發。 2.JavaScript靈活,廣泛用於前端和服務器端編程。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

ZendStudio 13.5.1 Mac
強大的PHP整合開發環境

mPDF
mPDF是一個PHP庫,可以從UTF-8編碼的HTML產生PDF檔案。原作者Ian Back編寫mPDF以從他的網站上「即時」輸出PDF文件,並處理不同的語言。與原始腳本如HTML2FPDF相比,它的速度較慢,並且在使用Unicode字體時產生的檔案較大,但支援CSS樣式等,並進行了大量增強。支援幾乎所有語言,包括RTL(阿拉伯語和希伯來語)和CJK(中日韓)。支援嵌套的區塊級元素(如P、DIV),

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

PhpStorm Mac 版本
最新(2018.2.1 )專業的PHP整合開發工具

Dreamweaver CS6
視覺化網頁開發工具