Skip to content

Commit

Permalink
Calculate automatically width and height of an image if is not specified
Browse files Browse the repository at this point in the history
  • Loading branch information
Luigi De Rosa committed Sep 5, 2014
1 parent ab1d330 commit 1fd4a85
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
4 changes: 1 addition & 3 deletions demos/grid/bird.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@

<div id="Frame1" class="focuspoint"
data-focus-x="0.29"
data-focus-y="-0.284"
data-image-w="667"
data-image-h="1000">
data-focus-y="-0.284">
<img src="../img/bird.jpg" alt="" />
</div>

Expand Down
19 changes: 19 additions & 0 deletions js/jquery.focuspoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,25 @@
image = $(this).find('img').first();
imageW = $(this).data('imageW');
imageH = $(this).data('imageH');

if (!imageW || !imageH) {
var self = this,
imageTmp = new Image();

imageTmp.onload = function(){

$(self).data('imageW', this.width);
$(self).data('imageH', this.height);

$(self).adjustFocus();
};

imageTmp.src = image.attr('src');

return false;
}


if (!(containerW > 0 && containerH > 0 && imageW > 0 && imageH > 0)) {
//Need dimensions to proceed
return false;
Expand Down

0 comments on commit 1fd4a85

Please sign in to comment.