Permalink
Browse files

Skipping visibility:hidden and display:none elements

  • Loading branch information...
1 parent a27290c commit 3c4581b5c4b3ac5a35835e189fab527e214bfe1f @niklasvh niklasvh committed Jul 17, 2011
Showing with 53 additions and 12 deletions.
  1. +2 −2 build/html2canvas.min.js
  2. +2 −2 src/Core.js
  3. +1 −1 src/Draw.js
  4. +9 −7 src/Traversing.js
  5. +39 −0 tests/visible-elements.html
View
Oops, something went wrong.
View
@@ -10,8 +10,8 @@ function html2canvas(el, userOptions) {
this.opts = this.extendObj(options, {
logging: false,
- ready: function (canvas) {
- document.body.appendChild(canvas);
+ ready: function (stack) {
+ document.body.appendChild(stack.canvas);
},
iframeDefault: "default",
flashCanvasPath: "http://html2canvas.hertzen.com/external/flashcanvas/flashcanvas.js",
View
@@ -3,7 +3,7 @@
html2canvas.prototype.newElement = function(el,parentStack){
-
+
var bounds = this.getBounds(el);
var x = bounds.left;
View
@@ -2,10 +2,10 @@
html2canvas.prototype.parseElement = function(element,ctx){
var _ = this;
- this.each(element.children,function(index,el){
+ this.each(element.children,function(index,el){
_.parsing(el,{
ctx:ctx
- });
+ });
});
this.canvasRenderer(this.contextStacks);
@@ -15,10 +15,12 @@ html2canvas.prototype.parseElement = function(element,ctx){
html2canvas.prototype.parsing = function(el,stack){
+
+ if (this.getCSS(el,'display') != "none" && this.getCSS(el,'visibility')!="hidden"){
+
+ var _ = this;
- var _ = this;
-
- //if (!this.blockElements.test(el.nodeName)){
+ //if (!this.blockElements.test(el.nodeName)){
stack = this.newElement(el,stack) || stack;
@@ -61,7 +63,7 @@ html2canvas.prototype.parsing = function(el,stack){
}
}
-
- // }
+ }
+// }
}
@@ -0,0 +1,39 @@
+<!--
+* @author Niklas von Hertzen <niklas at hertzen.com>
+* @created 16.7.2011
+* @website http://hertzen.com
+-->
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>Visible elements tests</title>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+ <link href="#" type="text/css" rel="stylesheet">
+
+ <script type="text/javascript" src="../external/jquery-1.6.2.min.js"></script>
+ <script type="text/javascript" src="../build/html2canvas.js"></script>
+ <script type="text/javascript" src="../build/jquery.plugin.html2canvas.js"></script>
+ <script type="text/javascript">
+ $(window).ready(function() {
+ new html2canvas($('body').get(0));
+ });
+ </script>
+
+ <style>
+ div{
+ border:2px solid black;
+ }
+ </style>
+
+ </head>
+ <body>
+ <h1>Display:none and visible:hidden tests</h1>
+ <div>This should be visible </div>
+ <div style="display:none">display:none, This should be <b>hidden</b></div>
+ <div style="visibility:hidden">visibility:hidden, This should be <b>hidden</b></div>
+ <hr />
+ <div style="display:none">display:none, This should be <b>hidden</b></div>
+ <div style="visibility:hidden">visibility:hidden, This should be <b>hidden</b></div>
+
+ </body>
+</html>

0 comments on commit 3c4581b

Please sign in to comment.