Skip to content

Commit

Permalink
Fixed annoying bug with canvas not resizing properly
Browse files Browse the repository at this point in the history
  • Loading branch information
mikefowler committed Jun 9, 2014
1 parent 3acb060 commit dd94732
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion demo/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ $(function () {

// Initialize both crossfade examples
$('.js-example-1').crossfade({
threshold: 0.2,
threshold: 0.2
});

$('.js-example-2').crossfade({
Expand Down
2 changes: 1 addition & 1 deletion dist/crossfade.jquery.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ <h3>Options</h3>
</tr>
<tr>
<th>backgroundPosition</th>
<td><em>Default: 'center center'</em><br>Determines the positioning of the background images. This option functions similarly to CSS background-size.</td>
<td><em>Default: 'center center'</em><br>Determines the positioning of the background images. Backgrounds are sized similarly to CSS's “background-size: cover”. This option determines along which edges the image is aligned.</td>
</tr>
</table>

Expand Down
8 changes: 6 additions & 2 deletions src/crossfade.jquery.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@
// and height are updated on window resize events.
this.canvas[0].width = this.width;
this.canvas[0].height = this.height;
this.canvas.css({
width: this.width,
height: this.height
});

};

Expand Down Expand Up @@ -168,7 +172,7 @@

// Draw the starting image…
this.paintbrush.drawImage(this.start[0], dimensions.offset.x, dimensions.offset.y, dimensions.width, dimensions.height);

// Set the global opacity based on the visibility of our element…
this.paintbrush.globalAlpha = this.visibility;

Expand All @@ -190,7 +194,7 @@
// --------------------------------------------------------------------------

Crossfade.prototype.getDrawDimensions = function (imageWidth, imageHeight, containerWidth, containerHeight) {

var dimensions = {};
var imageRatio = imageHeight / imageWidth;
var containerRatio = containerHeight / containerWidth;
Expand Down

0 comments on commit dd94732

Please sign in to comment.