誰可以建議kineticjs插件或腳本與jquery的「可排序」功能? 我需要創建一個拖放形狀的列表,並在元件的一次動作等元素在他的位置kineticjs模擬jquery可排序
0
A
回答
1
搬到這裏是一個腳本,讓用戶排序列表項的列表動力學通過拖動
之前:下圖顯示了用戶將項目#1拖到列表的底部。
後:此圖顯示了清單如何新排序順序自動重繪。
每個清單項目的數據內容存儲在項目對象的數組:
如果您需要更多的項目數據,只需將數據添加到列表項的對象
// array of item objects
var contents = [];
// item objects contain a text label
// and a reference to the Kinetic Group that displays this item
contents.push({ text: 」I’m list-item#1」, kItem: KineticGroup#1 });
在用戶將一個列表項拖到一個新位置後,整個列表被採用。
度假村訂單基於列表中每個列表項的「Y」座標。
該代碼重新繪製新排序順序中的所有列表項。
// after dragging, list is resorted by the "Y" coordinate of each list-item
function reorder(){
contents.sort(compare);
for(var i=0;i<contents.length;i++){
contents[i].kItem.setY((i*(itemHeight+itemSpacer))+itemsTopMargin);
}
layer.draw();
}
// custom compare function that sorts based on Y-coordinates
function compare(a,b){
if(a.kItem.getY()<b.kItem.getY()){ return -1; }
if(a.kItem.getY()>b.kItem.getY()){ return 1; }
return(0);
}
用戶完成拖拽排序後,將內容排列在用戶的順序排序
這裏的代碼和一個小提琴:http://jsfiddle.net/m1erickson/gZWvC/
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Prototype</title>
<script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>
<script src="http://d3lp1msu2r81bx.cloudfront.net/kjs/js/lib/kinetic-v4.5.4.min.js"></script>
<style>
#container{
border:solid 1px #ccc;
margin-top: 10px;
width:300px;
height:300px;
}
</style>
<script>
$(function(){
var stage = new Kinetic.Stage({
container: 'container',
width: 300,
height: 300
});
var layer = new Kinetic.Layer();
stage.add(layer);
// list item styling
var itemsTopMargin=20;
var itemWidth=100;
var itemHeight=25;
var itemX=30;
var itemSpacer=5;
var font="verdana";
var fontsize="16px";
// list item contents
var contents=[];
contents.push({text:"item#0",kItem:null});
contents.push({text:"item#1",kItem:null});
contents.push({text:"item#2",kItem:null});
contents.push({text:"item#3",kItem:null});
contents.push({text:"item#4",kItem:null});
// create the list items (kinetic groups)
for(var i=0;i<contents.length;i++){
addListItem(contents[i],i);
}
// after dragging, resort the list by "Y" coordinate
function reorder(){
contents.sort(compare);
for(var i=0;i<contents.length;i++){
contents[i].kItem.setY((i*(itemHeight+itemSpacer))+itemsTopMargin);
}
layer.draw();
}
function compare(a,b){
if(a.kItem.getY()<b.kItem.getY()){ return -1; }
if(a.kItem.getY()>b.kItem.getY()){ return 1; }
return(0);
}
// create a new list item
// a group containing a rect and text
function addListItem(content,i){
// group
// limit dragging to vertical drags only
var item=new Kinetic.Group({
x:itemX,
y:(i*(itemHeight+itemSpacer))+itemsTopMargin,
width:itemWidth,
height:itemHeight,
draggable:true,
dragBoundFunc:function(pos){
return({x:itemX,y:pos.y});
}
});
layer.add(item);
// starting drag -- move dragged item to top z-index
item.on("dragstart",function(){
this.moveToTop();
this.setOpacity(0.50);
});
// resort after user drags to desired position
item.on("dragend",function(){
this.setOpacity(1.00);
reorder();
});
// the list item rectangle
var rect=new Kinetic.Rect({
x:0,
y:0,
width:itemWidth,
height:itemHeight,
stroke:"skyblue",
fill:"lightgray"
});
item.add(rect);
// the list item label
var text=new Kinetic.Text({
x:10,
y:6,
text:content.text,
fill:"black"
});
item.add(text);
// store the k-group in the content
content.kItem=item;
layer.draw();
}
}); // end $(function(){});
</script>
</head>
<body>
<p>Sort by draggging item to new location</p>
<div id="container"></div>
</body>
</html>
+0
謝謝!很有幫助! – axon
相關問題
- 1. jQuery UI可排序:如何模擬'beforeStart'事件?
- 2. jquery可排序?
- 3. jQuery的可排序
- 4. Jquery UI可排序
- 5. jQuery的可排序
- 6. jQuery可排序 - PHP
- 7. jQuery可排序PHP
- 8. jquery可拖拽可排序
- 9. jQuery UI:可排序和可拖動的排序和排序
- 10. Jquery可排序 - 排序列表手冊
- 11. 我的jquery可排序不排序
- 12. 排序使用jQuery可排序
- 13. jQuery UI默認排序可排序
- 14. jQuery可排序 - 按ID查看排序
- 15. kineticjs線點的異步排序?
- 16. Javascript測試模擬拖動JQuery UI排序列表
- 17. Linux:數據包重新排序模擬
- 18. 我可以結合KineticJS和jQuery嗎?
- 19. JQuery可排序的滾動
- 20. jQuery的可排序的Widget
- 21. jQuery UI可排序動畫
- 22. 的jQuery可排序:避免
- 23. jQuery UI可排序圖像
- 24. JQuery可滾動排序
- 25. 可排序的jQuery iframeFix
- 26. jQuery可排序事件
- 27. jquery可排序項目
- 28. jQuery可排序IE問題
- 29. 啓用jQuery中可排序
- 30. 擴展jQuery可排序Dropzone
嘿,我想kineticjs插件應該正如名稱本身所說的「企業..網絡圖形」一樣。 –