admin管理员组文章数量:1287606
I'm working on a script for manipulating pictures and saving it to an image.
I have a div where i set a background image and in that div i have another div with an image which i manipulate (resize,rotate and drag around). Everything is working fine, i receive an image, resize and position styles are applied correctly, only rotate style is reverted back to zero degree angle, that is horizontally. Is there any workaround?
My code,
HTML:
<div id="canvas">
<div id="imgdiv">
<img id="slika1" src="images/ocala.png"/>
</div>
</div>
<div id="bottom">
<button id="shrani">
Download
</button>
</div>
CSS:
#canvas {
float: left;
width: 69%;
height: 400px;
border: 1px solid red;
background-image: url('../images/face.jpg');
background-size: 80% 100%;
background-repeat: no-repeat;
background-position: center;
z-index: 1;
}
#imgdiv {//
border: 1px solid #000000;
display: inline-block;
z-index: 2;
}
Javascript
//rotating code, i have a slider in div next to "canvas" div
var img = $("#imgdiv");
$("#rotate").slider({
min : -180,
max : 180,
value : 0,
change : function(event, ui) {
if (event.originalEvent) {
img.css('-moz-transform', 'rotate(' + ui.value + 'deg)');
img.css('-webkit-transform', 'rotate(' + ui.value + 'deg)');
img.css('-o-transform', 'rotate(' + ui.value + 'deg)');
img.css('-ms-transform', 'rotate(' + ui.value + 'deg)');
kot = ui.value;
} else {
}
}
});
//html2canvas code
$("#shrani").click(function() {
html2canvas($("#canvas"), {
onrendered : function(canvas) {
var data = canvas.toDataURL();
window.open(data);
}
});
});
I'm working on a script for manipulating pictures and saving it to an image.
I have a div where i set a background image and in that div i have another div with an image which i manipulate (resize,rotate and drag around). Everything is working fine, i receive an image, resize and position styles are applied correctly, only rotate style is reverted back to zero degree angle, that is horizontally. Is there any workaround?
My code,
HTML:
<div id="canvas">
<div id="imgdiv">
<img id="slika1" src="images/ocala.png"/>
</div>
</div>
<div id="bottom">
<button id="shrani">
Download
</button>
</div>
CSS:
#canvas {
float: left;
width: 69%;
height: 400px;
border: 1px solid red;
background-image: url('../images/face.jpg');
background-size: 80% 100%;
background-repeat: no-repeat;
background-position: center;
z-index: 1;
}
#imgdiv {//
border: 1px solid #000000;
display: inline-block;
z-index: 2;
}
Javascript
//rotating code, i have a slider in div next to "canvas" div
var img = $("#imgdiv");
$("#rotate").slider({
min : -180,
max : 180,
value : 0,
change : function(event, ui) {
if (event.originalEvent) {
img.css('-moz-transform', 'rotate(' + ui.value + 'deg)');
img.css('-webkit-transform', 'rotate(' + ui.value + 'deg)');
img.css('-o-transform', 'rotate(' + ui.value + 'deg)');
img.css('-ms-transform', 'rotate(' + ui.value + 'deg)');
kot = ui.value;
} else {
}
}
});
//html2canvas code
$("#shrani").click(function() {
html2canvas($("#canvas"), {
onrendered : function(canvas) {
var data = canvas.toDataURL();
window.open(data);
}
});
});
Share
Improve this question
asked Nov 20, 2013 at 12:09
gregajgregaj
3381 gold badge6 silver badges15 bronze badges
8
- Can you create JSFiddle please? – Boris Ivanov Commented Nov 20, 2013 at 12:15
- Instead of pictures i used divs for demonstration purpose. jsfiddle/g5GGb/10 – gregaj Commented Nov 20, 2013 at 13:08
- But how you suppose to work with canvas without canvas HTML tag? Look at this example stackoverflow./questions/10673122/… – Boris Ivanov Commented Nov 20, 2013 at 15:06
- Dont be confused with "canvas" div, it is not meant as canvas element. As i understand this: html2canvas converts my "#canvas" div and its elements to actual canvas element(creates an image) and then sends it to a new window. Like i said everything works fine, i can even save an image as png, the only problem i have is that css style "rotate" is not applied correctly after i convert my div to image/canvas. – gregaj Commented Nov 20, 2013 at 20:35
- Nobody experienced the same thing? – gregaj Commented Nov 21, 2013 at 11:15
2 Answers
Reset to default 2I know this question is ancient, and you're no doubt over it by now. But I believe
- Transform support is improved, and
- It may still not work with your code because you're using only the browser-specific transforms and nowhere are you setting simply
img.css('transform', 'rotate(' + ui.value + 'deg)');
For what it's worth, my layers are rotated and it's working fine. What's not working is opacity, but I'll leave that for another post.
It seems as though CSS transforms are not yet fully supported by html2canvas. See here:
https://github./niklasvh/html2canvas/issues/184 https://github./niklasvh/html2canvas/issues/220
本文标签: javascripthtml2canvasstyles not applied to canvasStack Overflow
版权声明:本文标题:javascript - html2canvas, styles not applied to canvas? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741317170a2371984.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论