Skip to content

make large image fit the screen #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: gh-pages
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,29 @@ $.fn.popImg = function() {
$c.css("cursor", "zoom-out").attr("data-b-img", 1);
var img = new Image();
img.onload = function(){
/*
* define big image size
*/
//make new size by default
var bigImageHeight = ($(window).height()*.9).toFixed(0);
var bigImageWidth = (this.width*bigImageHeight/this.height).toFixed(0);
//if the big image over range of the screen,use width of the original image for new image size setting
if(bigImageWidth > $(window).width())
{
bigImageWidth = ($(window).width()*.9).toFixed(0);
bigImageHeight = (this.height*bigImageWidth/this.width).toFixed(0);
}
//if the new image is larger than the original one,let's use the original image size
bigImageWidth = bigImageWidth>this.width?this.width:bigImageWidth;
bigImageHeight = bigImageHeight>this.height?this.height:bigImageHeight;
/*
* end
*/
$c.stop().animate({
width: this.width,
height: this.height,
left: (dW - this.width) / 2,
top: (dH - this.height) / 2
width: bigImageWidth,
height: bigImageHeight,
left: (dW - bigImageWidth) / 2,
top: (dH - bigImageHeight) / 2
}, 300);
};
img.src = $c.attr("src");
Expand Down