習的道路就是要不斷的總結歸納,好記性不如爛筆頭。但是,毫無邏輯的總結,并無太大意義,一份有規劃有流程的總結往往能有事半功倍的作用。
下面小編將Po出11張JavaScript相關的思維導圖,圖片高清,建議WiFi下查看,土豪隨意。分別歸類為:
Javascript變量
Javascript運算符
Javascript數組
Javascript流程語句
Javascript數據類型
Javascript字符串函數
Javascript函數基礎
Javascript基礎DOM操作
Javascript正則表達式
Jquery知識結構圖
Window對象
能夠認真看完就是一次對Javascript的回顧與提升,可以很好的檢驗基礎。希望多大家學習和成長有用。
注:文章綜合自博客園、CSDN等平臺,最終解釋權歸原作者所有,侵刪。做一只IT干貨的搬運工,只為成就更好的你!
我們的開發工程中經常會使用到各種圖,所謂的圖就是由節點和節點之間的連接所形成的系統,數學上專門有一個分支叫圖論(Graph Theroy)。利用圖我們可以做很多工具,比如思維導圖,流程圖,狀態機,組織架構圖,等等。今天我要做的是用開源的HTML5工具來快速構造一個做圖的工具。
工預善其事,必先利其器。第一件事是選擇一件合適的工具,開源時代,程序員還是很幸福的,選擇很多。
最終,我選擇了jsPlumb,因為它完全開源,使用很簡單,用D3的話可能會多花很多功夫。joint.js也不錯。大家可以根據自己的需要選擇。
下面我們一步一步的來使用jsPlumb來創建我們的流程圖工具。
第一步是等待DOM和jsPlumb初始化完畢,類似document.ready()和jquery.ready(), 要使用jsPlumb, 需要把代碼放在這個函數里:
jsPlumb.ready(function()?{ ????//?...?your?code?goes?here?... }
創建一個jsPlumb的實例,并初始化jsPlumb的配置參數:
//Initialize?JsPlumb var?color?=?"#E8C870"; var?instance?=?jsPlumb.getInstance({ ????//?notice?the?'curviness'?argument?to?this?Bezier?curve.??the?curves?on?this?page?are?far?smoother ????//?than?the?curves?on?the?first?demo,?which?use?the?default?curviness?value.?????? ????Connector?:?[?"Bezier",?{?curviness:50?}?], ????DragOptions?:?{?cursor:?"pointer",?zIndex:2000?}, ????PaintStyle?:?{?strokeStyle:color,?lineWidth:2?}, ????EndpointStyle?:?{?radius:5,?fillStyle:color?}, ????HoverPaintStyle?:?{strokeStyle:"#7073EB"?}, ????EndpointHoverStyle?:?{fillStyle:"#7073EB"?}, ????Container:"container-id" ?});
這里給給出了一些配置包括,連接線(這里配置了一個貝塞爾曲線),線的風格,連接點得風格。Container需要配置一個對應的DIV容器的id。(這里也可以使用setContainer的方法)
下面我們要創建一個節點(node),每一個節點可以用一個DIV來實現。我這里提供了一個函數來創建節點。
function?addNode(parentId,?nodeId,?nodeLable,?position)?{ ??var?panel?=?d3.select("#"?+?parentId); ??panel.append('div').style('width','120px').style('height','50px') ????.style('position','absolute') ????.style('top',position.y).style('left',position.x) ????.style('border','2px?#9DFFCA?solid').attr('align','center') ????.attr('id',nodeId).classed('node',true) ????.text(nodeLable); ??return?jsPlumb.getSelector('#'?+?nodeId)[0]; }
這里做的事情就是創建了一個DIV元素,并放在對應的容器的制定位置上,注意為了支持拖拽的功能,必須使用position:absolute 。
我使用D3來操作DOM,大家可能會更習慣JQuery,這純屬個人喜好的問題。
最后返回創建節點的實例引用,這是的selector使用了jsPlumb.getSelector()方法,它和JQuery的selector是一樣的,這樣用的好處是你可以使用不同的DOM操作庫,例如Vanilla
下面我使用一個函數來創建端點/錨點(anchor),錨點就是節點上的連接點,用于連接不同的節點。
function?addPorts(instance,?node,?ports,?type)?{ ??//Assume?horizental?layout ??var?number_of_ports?=?ports.length; ??var?i?=?0; ??var?height?=?$(node).height();??//Note,?jquery?does?not?include?border?for?height ??var?y_offset?=?1?/?(?number_of_ports?+?1); ??var?y?=?0; ??for?(?;?i?<?number_of_ports;?i++?)?{ ????var?anchor?=?[0,0,0,0]; ????var?paintStyle?=?{?radius:5,?fillStyle:'#FF8891'?}; ????var?isSource?=?false,?isTarget?=?false; ????if?(?type?===?'output'?)?{ ??????anchor[0]?=?1; ??????paintStyle.fillStyle?=?'#D4FFD6'; ??????isSource?=?true; ????}?else?{ ??????isTarget?=true; ????} ????anchor[1]?=?y?+?y_offset; ????y?=?anchor[1]; ????instance.addEndpoint(node,?{ ??????uuid:node.getAttribute("id")?+?"-"?+?ports[i], ??????paintStyle:?paintStyle, ??????anchor:anchor, ??????maxConnections:-1, ??????isSource:isSource, ??????isTarget:isTarget ????}); ??} }
instance是jsPlumb的實例
node是我們用addNode方法創建的Node實例
ports,是一個string的數組,指定端點的個數和名字
type,可能是output或者input,指定端點的種類,一個節點的輸出端口可以連接另一個節點的輸入端口。
這里anchor是一個四維數組,0維和1維分別是錨點在節點x軸和y軸的偏移百分比。我這里希望把端口畫在節點的左右兩側,并按照端口的數量均勻分布。
最后使用instance.addEndpoint來創建端點。注意這里只要指定isSource和isTarget就可以用drag&drop的方式來連接端點,非常方便。
下面一步我們提供一個函數來連接端點:
function?connectPorts(instance,?node1,?port1,?node2?,?port2)?{ ??//?declare?some?common?values: ??var?color?=?"gray"; ??var?arrowCommon?=?{?foldback:0.8,?fillStyle:color,?width:5?}, ??//?use?three-arg?spec?to?create?two?different?arrows?with?the?common?values: ??overlays?=?[ ????[?"Arrow",?{?location:0.8?},?arrowCommon?], ????[?"Arrow",?{?location:0.2,?direction:-1?},?arrowCommon?] ??]; ??var?uuid_source?=?node1.getAttribute("id")?+?"-"?+?port1; ??var?uuid_target?=?node2.getAttribute("id")?+?"-"?+?port2; ??instance.connect({uuids:[uuid_source,?uuid_target]}); }
node1和node2是源節點和目標節點的引用,port1和port2是源端口和目標端口的名字。
使用instance.connect方法來創建連接。 overlays用來添加連接線的箭頭效果或者其他風格,我這里沒有使用,因為覺得都不是很好看。大家如果要用,只要把overlays加入到instance.connect的方法參數就可以了。
調用以上方法來創建節點,端點和連接線。
var?node1?=?addNode('container-id','node1',?'node1',?{x:'80px',y:'20px'}); var?node2?=?addNode('container-id','node2',?'node2',?{x:'280px',y:'20px'}); addPorts(instance,?node1,?['out1','out2'],'output'); addPorts(instance,?node2,?['in','in1','in2'],'input'); connectPorts(instance,?node1,?'out2',?node2,?'in');
這里我們創建了兩個節點,第一個節點有兩個輸出端口,第二個節點有三個輸入端口,然后把第一個節點的out2端口連接到第二個端點的in端口。效果如下:
最后我們給節點增加drag&drop的功能,這樣我們就可以拖動這些節點來改變圖的布局了。
instance.draggable($('.node'));
這里似乎依賴于JQuery-UI,我還不是很清楚。
我們已經初步具有了創建圖的功能,可是節點的創建必須通過程序,我們希望用交互的方式來創建節點。
通常我們希望有一個tree view的控件,讓后通過拖拽來創建對應類型的節點。這里我使用了這個開源的tree view,基于bootstrap https://github.com/jonmiles/bootstrap-treeview
我們先創建一個tree view:
function?getTreeData()?{ ??var?tree?=?[ ????{ ??????text:?"Nodes", ??????nodes:?[ ????????{ ??????????text:?"Node1", ????????}, ????????{ ??????????text:?"Node2" ????????} ??????] ????} ??];? ??return?tree; } //Initialize?Control?Tree?View $('#control-panel').treeview({data:?getTreeData()});
樹上有兩個節點:
然后我實現從樹上拖拽對應的節點,到流程圖上的邏輯。
//Handle?drag?and?drop $('.list-group-item').attr('draggable','true').on('dragstart',?function(ev){ ??//ev.dataTransfer.setData("text",?ev.target.id); ??ev.originalEvent.dataTransfer.setData('text',ev.target.textContent); ??console.log('drag?start'); }); $('#container-id').on('drop',?function(ev){ ??//avoid?event?conlict?for?jsPlumb ??if?(ev.target.className.indexOf('_jsPlumb')?>=?0?)?{ ????return; ??} ??ev.preventDefault(); ??var?mx?=?''?+?ev.originalEvent.offsetX?+?'px'; ??var?my?=?''?+?ev.originalEvent.offsetY?+?'px'; ??console.log('on?drop?:?'?+?ev.originalEvent.dataTransfer.getData('text')); ??var?uid?=?new?Date().getTime(); ??var?node?=?addNode('flow-panel','node'?+?uid,?'node',?{x:mx,y:my}); ??addPorts(instance,?node,?['out'],'output'); ??addPorts(instance,?node,?['in1','in2'],'input'); ??instance.draggable($(node)); }).on('dragover',?function(ev){ ??ev.preventDefault(); ??console.log('on?drag?over'); });
這里要注意的是要避免和jsPlumb拖拽端點的邏輯沖突,當檢測到target是jsPlumb對象是需要直接從drop方法中退出以執行對應的jsPlumb的drop邏輯。
好了,一個繪制流程圖的軟件工具初步完工。
我把代碼放在oschina的代碼托管服務上了, 大家有興趣可以去試試。
給大家看一張喜歡的圖片,緩解下心情,最近敲敲代碼累的時候都會看看這幾個小活寶,每次都忍不住伸手去摸一下屏幕,可愛到爆,不由自主的就笑了出來。這個是電影《鼠來寶》系列的海報圖。不知道有沒有人喜歡這幾只會唱歌的小活寶。
這幾天看了 一下之前整理的html和css的知識點,發現很多東西都有點忘了,趁此機會,復習了一下,也重新整理了一下,決定放出來,也給剛入門的孩紙們一個參考,之前有簡友說圖片看不清,電腦的話可以點擊放大,或者另存為,放大還是挺清楚的,手機app也可以下載圖片或者放大,其實可以下載下來,地鐵上或者等人的時候,拿出手機看一看,感覺還可以。
圖片比較大,建議大家看的時候先看下分支,然后點擊放大查看具體,如果有Xmind軟件的小伙伴也可以私聊我要文件
第一張 HTML基本結構與css選擇器
主要介紹html的基本結構和css選擇器,話不多說,都在圖里。
基本概括.png
第二張 html常用基本標簽
html基本標簽
已分類,需要注意的部分已標注。看完這一張,還有下一張。
HTML標簽.png
第三張 CSS的常用屬性
主要介紹css的屬性
css屬性.png
第四張 表格和表單
表格和表單.png
第五張 浮動、定位、overflow
浮動、定位、overflow.png
第六張 補充小知識
小知識.png
最后給大家給大家詳細說一下border-radius的用法
普通用法不做詳細介紹;
其實我們設置border-radius參數的時候,最多可以設置8個參數,每個參數的位置和代指圓角方向已經在圖上表明;簡單明了。
示意圖.jpg
下面放一張我主要用 border-radius 畫的一個小企鵝(命名比較low,可以忽略 。)
最后的效果圖
QQ小企鵝.PNG
html標簽部分
<div class="qie"> <!-- 頭部 --> <div class="tou"> <div class="eye_1"> <div class="eye_1_1"></div> </div> <div class="eye_2"> <div class="eye_2_1"></div> <div class="eye_2_2"></div> </div> <div class="zui"></div> <div class="tou_2"></div> </div> <!-- 圍巾 --> <div class="weijin"> <div class="weijin_left"></div> <div class="weijin_content"></div> <div class="weijin_right"></div> <div class="weijin_bottom"></div> <div class="weijin_1"></div> </div> <!-- 身體 --> <div class="body"> <div class="duzi"></div> <div class="hand"></div> <div class="hand_2"></div> </div> <!-- 腳 --> <div class="footer"></div> </div>
css樣式部分
.qie{ margin-left: auto; margin-right: auto; width: 200px; } .tou{ height: 80px; width: 120px; background-color: #000; border-radius: 60px 60px 0px 0px; position: relative; } .eye_1,.eye_2{ width: 20px; height: 30px; background-color: #fff; border-radius: 10px 10px 10px 10px/15px 15px 15px 15px; } .eye_1{ position: absolute; left: 35px; top: 25px } .eye_2{ position: absolute; right:35px; top: 25px; } .eye_1_1{ height: 13px; width: 10px; background-color: #000; border-radius: 5px 5px 5px 5px/6px 6px 6px 6px; position: absolute; left: 9px; top:10px; } .eye_2_1{ height: 6px; width: 15px; background-color: #000; border-radius: 7px 7px 0px 0px/6px 6px 0px 0px; position: absolute; left: 2px; top: 12px; } .eye_2_2{ width: 13px; height: 6px; background-color: #fff; border-radius: 6px 6px 0px 0px/6px 6px 0px 0px; position: absolute; left: 3px; top: 14px; } .zui{ height: 20px; width: 72px; background-color: #ffad00; border-radius: 36px 36px 36px 36px/8px 8px 12px 12px; position: absolute; left: 23px; top: 58px; } .tou_2{ height: 10px; width: 120px; background-color: #000; position: absolute; top: 80px; border-radius: 0 0 62px 62px/ 0 0 10px 10px; z-index: 3; } .weijin{ position: relative; z-index: 2; } .weijin_left{ height: 0px; width: 0px; border-style: solid; border-width: 10px 5px; border-color: transparent #e91f1f #e91f1f transparent ; position: absolute; left: -9px; } .weijin_content{ height: 20px; width: 120px; background-color: #e91f1f; } .weijin_right{ height: 0px; width: 0px; border-style: solid; border-width: 10px 5px; border-color: transparent transparent #e91f1f #e91f1f ; position: absolute; left: 120px; bottom:0px; } .weijin_bottom{ height: 10px; width: 140px; background-color: #e91f1f; border-radius: 0 0 70px 70px/0 0 10px 10px; position: absolute; left: -10px } .weijin_1{ height: 30px; width: 24px; background-color: #e91f1f; position: absolute; left: 20px; } .body{ height: 85px; width: 120px; background-color: #000; border-radius: 0 0 60px 60px/0 0 50px 50px; position: relative; z-index: 1 } .duzi{ height: 78px; width: 90px; background-color: #fff; border-radius: 0 0 45px 45px/0 0 45px 45px; position: absolute; left: 15px; } .hand{ height: 54px; width: 20px; background-color:#000; z-index: 4px; position: absolute; left: -18px; top: -4px; border-radius: 18px 0px 18px 2px/52px 0px 28px 2px ; } .hand_2{ height: 54px; width: 20px; background-color:#000; z-index: 4px; position: absolute; right: -18px; top: -4px; border-radius:0px 18px 2px 18px / 0px 52px 2px 28px } .footer{ height: 16px; width: 120px; background-color: #fcb117; border-radius: 40px 40px 3px 3px/13px 13px 2px 2px; position: relative; bottom: 16px; }
如果看的不舒服,合在一起給你看
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <style type="text/css"> .qie{ margin-left: auto; margin-right: auto; width: 200px; } .tou{ height: 80px; width: 120px; background-color: #000; border-radius: 60px 60px 0px 0px; position: relative; } .eye_1,.eye_2{ width: 20px; height: 30px; background-color: #fff; border-radius: 10px 10px 10px 10px/15px 15px 15px 15px; } .eye_1{ position: absolute; left: 35px; top: 25px } .eye_2{ position: absolute; right:35px; top: 25px; } .eye_1_1{ height: 13px; width: 10px; background-color: #000; border-radius: 5px 5px 5px 5px/6px 6px 6px 6px; position: absolute; left: 9px; top:10px; } .eye_2_1{ height: 6px; width: 15px; background-color: #000; border-radius: 7px 7px 0px 0px/6px 6px 0px 0px; position: absolute; left: 2px; top: 12px; } .eye_2_2{ width: 13px; height: 6px; background-color: #fff; border-radius: 6px 6px 0px 0px/6px 6px 0px 0px; position: absolute; left: 3px; top: 14px; } .zui{ height: 20px; width: 72px; background-color: #ffad00; border-radius: 36px 36px 36px 36px/8px 8px 12px 12px; position: absolute; left: 23px; top: 58px; } .tou_2{ height: 10px; width: 120px; background-color: #000; position: absolute; top: 80px; border-radius: 0 0 62px 62px/ 0 0 10px 10px; z-index: 3; } .weijin{ position: relative; z-index: 2; } .weijin_left{ height: 0px; width: 0px; border-style: solid; border-width: 10px 5px; border-color: transparent #e91f1f #e91f1f transparent ; position: absolute; left: -9px; } .weijin_content{ height: 20px; width: 120px; background-color: #e91f1f; } .weijin_right{ height: 0px; width: 0px; border-style: solid; border-width: 10px 5px; border-color: transparent transparent #e91f1f #e91f1f ; position: absolute; left: 120px; bottom:0px; } .weijin_bottom{ height: 10px; width: 140px; background-color: #e91f1f; border-radius: 0 0 70px 70px/0 0 10px 10px; position: absolute; left: -10px } .weijin_1{ height: 30px; width: 24px; background-color: #e91f1f; position: absolute; left: 20px; } .body{ height: 85px; width: 120px; background-color: #000; border-radius: 0 0 60px 60px/0 0 50px 50px; position: relative; z-index: 1 } .duzi{ height: 78px; width: 90px; background-color: #fff; border-radius: 0 0 45px 45px/0 0 45px 45px; position: absolute; left: 15px; } .hand{ height: 54px; width: 20px; background-color:#000; z-index: 4px; position: absolute; left: -18px; top: -4px; border-radius: 18px 0px 18px 2px/52px 0px 28px 2px ; } .hand_2{ height: 54px; width: 20px; background-color:#000; z-index: 4px; position: absolute; right: -18px; top: -4px; border-radius:0px 18px 2px 18px / 0px 52px 2px 28px } .footer{ height: 16px; width: 120px; background-color: #fcb117; border-radius: 40px 40px 3px 3px/13px 13px 2px 2px; position: relative; bottom: 16px; } </style> </head> <body> <div class="qie"> <!-- 頭部 --> <div class="tou"> <div class="eye_1"> <div class="eye_1_1"></div> </div> <div class="eye_2"> <div class="eye_2_1"></div> <div class="eye_2_2"></div> </div> <div class="zui"></div> <div class="tou_2"></div> </div> <!-- 圍巾 --> <div class="weijin"> <div class="weijin_left"></div> <div class="weijin_content"></div> <div class="weijin_right"></div> <div class="weijin_bottom"></div> <div class="weijin_1"></div> </div> <!-- 身體 --> <div class="body"> <div class="duzi"></div> <div class="hand"></div> <div class="hand_2"></div> </div> <!-- 腳 --> <div class="footer"></div> </div> </body> </html>
字少,圖多,還請想學習的菜鳥耐心點,嘿嘿。
*請認真填寫需求信息,我們會在24小時內與您取得聯系。