Comments (5)
Do you have an example? A page will be scrolled if there are no dragging nodes on stage.
from konva.
thanks, lavrton!
I have a more serious problem now, when in ipad, the safari will crash when i create lots of stage and layer, i don't konw why it's happend, can you help me? this is my create stage code. when i call three thimes 'createStandardLayout' , and the row and col is 2, the safari crashed!
var Konva = Konva || {};
(function () {
Konva.Util.addMethods(EWorldWebViewer.Gui.LayoutCreator, {
___init: function (config) {
this._id_container = 'center';
},
/*
* 创建标准的布局格式
* @param {Int} rows 行数
* @param {Int} cols 列数
* @param {Int} index 索引号
* @return {EWorldWebViewer.Models.Layout}
*/
createStandardLayout: function (rows, cols, index) {
var layout = new EWorldWebViewer.Models.Layout();
layout._rows = rows;
layout._cols = cols
layout._id = "layout_" + index; // 设置ID
// 选择ID
while (true) {
if ($("#" + layout._id).length > 0) {
// Id已经存在
//console.error("Id:" + layout._id + "已经存在");
index += 1;
layout._id = "layout_" + index; // 设置ID
} else {
break;
}
}
// 计算整个Layout的高度和宽度
var layHeight = $("#" + this._id_container).height();
var layWidth = $("#" + this._id_container).width();
$("<div>", {
'id': layout._id,
'class': 'layout-container',
'css': {
'height': layHeight,
'width': layWidth,
'position': 'absolute',
'background-color': '#666',
'left': 0,
'top': 1,
'z-index': index
}
}).appendTo("#" + this._id_container);
// 创建Viewers
this.createViewers(layout);
return layout;
},
/*
* 创建影像显示窗口
* @param {EWorldWebViewer.Models.Layout} layout
*/
createViewers: function(layout){
// 清空
layout.clearViewer();
// 计算每个View的尺寸
var layHeight = $('#' + layout._id).height();
var layWidth = $('#' + layout._id).width();
// 横向边框数目
var border_count_h = layout._cols + 1;
// 纵向边框数目
var border_count_v = layout._rows + 1;
var vHeight = parseInt((layHeight - border_count_v) / layout._rows);
var vWidth = parseInt((layWidth - border_count_h) / layout._cols);
for (var r = 0; r < layout._rows; ++r) {
for (var c = 0; c < layout._cols; ++c) {
var viewer = new EWorldWebViewer.Models.Viewer();
viewer._id = layout._id + '_viewer_' + (r * layout._cols + c);
$("<div>", {
'id': viewer._id,
'class': 'subseries',
'css': {
'width': vWidth,
'height': vHeight,
'position': 'absolute',
'left': (vWidth) * c + (c + 1),
'top': (vHeight) * r + (r + 1),
'background': '#000'
}
}).appendTo('#' + layout._id);
viewer._viewerWidth = vWidth;
viewer._viewerHeight = vHeight;
// 创建舞台
viewer._stage = new Konva.Stage({
container: viewer._id,
id: viewer._id + "_stage",
width: vWidth - 2,
height: vHeight - 2
});
/*事件绑定*/
if (viewer._stage) {
if (Konva.UA.mobile) {
//viewer._stage.on("touchstart", eWorldWebApp._htmlGen._imageViewPage._eventHandle.event_handle_stage_touch_start());
viewer._stage.on("contentTouchstart", EWorldWebViewer.eWorldWebApp._htmlGen._imageViewPage._eventHandle.event_handle_stage_touch_start());
//viewer._stage.on("touchmove", eWorldWebApp._htmlGen._imageViewPage._eventHandle.event_handle_stage_mouse_move());
viewer._stage.on("contentTouchmove", EWorldWebViewer.eWorldWebApp._htmlGen._imageViewPage._eventHandle.event_handle_stage_mouse_move());
viewer._stage.on("contentDbltap", EWorldWebViewer.eWorldWebApp._htmlGen._imageViewPage._eventHandle.event_handle_stage_dbclick());
//viewer._stage.on("touchend", eWorldWebApp._htmlGen._imageViewPage._eventHandle.event_handle_stage_touch_end());
viewer._stage.on("contentTouchend", EWorldWebViewer.eWorldWebApp._htmlGen._imageViewPage._eventHandle.event_handle_stage_touch_end());
} else {
//viewer._stage.on("mousemove", eWorldWebApp._htmlGen._imageViewPage._eventHandle.event_handle_stage_mouse_move());
viewer._stage.on("contentMousemove", EWorldWebViewer.eWorldWebApp._htmlGen._imageViewPage._eventHandle.event_handle_stage_mouse_move());
viewer._stage.on("mousewheel", EWorldWebViewer.eWorldWebApp._htmlGen._imageViewPage._eventHandle.event_handle_stage_mouse_wheel());
viewer._stage.on("contentMousedown", EWorldWebViewer.eWorldWebApp._htmlGen._imageViewPage._eventHandle.event_handle_stage_mouse_down());
viewer._stage.on("contentMouseup", EWorldWebViewer.eWorldWebApp._htmlGen._imageViewPage._eventHandle.event_handle_stage_mouse_up());
viewer._stage.on("contentMouseover", EWorldWebViewer.eWorldWebApp._htmlGen._imageViewPage._eventHandle.event_handle_stage_mouse_over());
viewer._stage.on("contentMouseout", EWorldWebViewer.eWorldWebApp._htmlGen._imageViewPage._eventHandle.event_handle_stage_mouse_out());
viewer._stage.on("dblclick", EWorldWebViewer.eWorldWebApp._htmlGen._imageViewPage._eventHandle.event_handle_stage_dbclick());
}
}
// 创建绘图层
this.createCanvasLays(viewer);
layout._viewers.push(viewer);
// 创建选中块
$("<div>", {
'id': viewer._id + '_selector',
'class': 'viewer_selector',
'css': {
'width': '10px',
'height': '10px',
'position': 'absolute',
'background': '#ff0',
'right': 0,
'bottom': 0,
'display': 'none'
}
}).appendTo('#' + viewer._id);
// 添加滚动条
var sliderTop = vHeight - 30;
var sliderDivWidth = vWidth / 3;
var sliderLeft = (vWidth - sliderDivWidth) / 2;
var sliderWidth = sliderDivWidth - 56;
var sliderId = viewer._id + "_slider";
var htmlScroll =
'<div class="viewer_slider" id="' + sliderId + '" style="left: '+ sliderLeft +'px; top: ' + sliderTop + 'px; width: '+ sliderDivWidth +'px; height: 25px; position: absolute; background:#000; filter:alpha(Opacity=80);-moz-opacity:0.5;opacity: 0.5; display:none">' +
'<button class="button button-tiny button-inverse-flat button-circle" style="float:left">' +
'<i class="fa fa-angle-left"></i>' +
'</button>' +
'<div class="slider_d" style="width:' + sliderWidth + 'px;height:10px; margin: 10px 1px 0px 1px; position:relative;left:28px"></div>' +
'<button class="button button-tiny button-inverse-flat button-circle" style="float:right">' +
'<i class="fa fa-angle-right"></i>' +
'</button>' +
'</div>';
$("#" + viewer._id).append(htmlScroll);
// 创建加载进度
EWorldWebViewer.eWorldWebApp._htmlGen.genProgress(viewer);
}
}
$('.slider_d').slider({
max: 100,
min: 0,
step: 1
});
},
/*
* 创建绘图层
*/
createCanvasLays: function (viewer) {
viewer._layer_image = new Konva.Layer();
viewer._stage.add(viewer._layer_image);
viewer._layer_annon = new Konva.Layer();
viewer._stage.add(viewer._layer_annon);
viewer._layer_annon_temp = new Konva.Layer();
viewer._stage.add(viewer._layer_annon_temp);
viewer._layer_anchor = new Konva.Layer();
viewer._stage.add(viewer._layer_anchor);
viewer._layer_dcminfo = new Konva.Layer();
viewer._stage.add(viewer._layer_dcminfo);
viewer._layer_ct = new Konva.Layer();
viewer._stage.add(viewer._layer_ct);
viewer._layer_refline = new Konva.Layer();
viewer._stage.add(viewer._layer_refline);
}
});
})();
from konva.
@DMIAOCHEN So how many layer you have? Having a lot of canvas elements on page is not a good way.
from konva.
I think so too, there are at least six stage and one stage has seven layers before, now i have delete some layers, remain two layer in one stage, and do not call destroyChildren and new shape every times, use find to get the existing shape instead, then this is more better!
thanks a lot~ now i finally found konvajs is high performance framework!^_^
from konva.
👍
from konva.
Related Issues (20)
- Rotating the object image using the rotate function HOT 2
- Documentation for old releases and migration guide HOT 1
- comment typo HOT 1
- Can't cornerRadius and shadow be shared on the react-Konva Image component? HOT 1
- `canvas` dependency missing for node HOT 2
- Smooth Scrolling of Bitmap Render on LED Display HOT 3
- Feature Request: Transformer support custom create anchor HOT 3
- determine length of a line given its points and tension HOT 2
- What is the correct way to fire a custom event using react-konva HOT 1
- Rotated circle size HOT 1
- Event when you mousedown and move outside canvas. HOT 1
- Can we draw an un-closed ellipse like below? HOT 1
- Text wrong line break if have Chinese and english word
- Broken shadow after crop in safari HOT 3
- Problem with Loading Video (Konva.Node.create) HOT 1
- After caching the lines, if there is a scaling factor, the line width may appear abnormal
- Vertical text position is different between Safari and other browsers HOT 2
- Konva React Text - Cannot use SVG for text pattern HOT 1
- Different scaling behavior on SVGs in different browsers HOT 1
- path fill miss somre area HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from konva.