/    Sign up×
Community /Pin to ProfileBookmark

browser resize : image problem

Hi,

I’ve been messing about with some javascript to ensure my image fills the entire height of the screen when resized.

However, I also want to set a min height which is controlled by an if statement. I.e. IF browser height is resized to less than 900px do not shrink the image any further as it would make the site too small.

I’m sure it is really basic to do but i’m struggling like mad!

Here is my code, any advice or solutions would be brill as i’m currently pulling my hair out.

(oh yeah… img.source-image is the class of the resizing image)

<script type=”text/javascript”>
$(document).ready(function() {

var $winheight = $(window).height();
$(“img.source-image”).attr({
height: $winheight
});

$(window).bind(“resize”, function(){
var $wineheight = $(window).height();
var test = $wineheight
if(test<900)
{

document.getElementById(“img.source-image”).style.minHeight=”900px”;
}

$(“img.source-image”).attr({
height: $wineheight
});
});
});

</script>

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @tescgo spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...