Comments 3Per started the conversationJanuary 21, 2019 at 9:36pmHello,Is it possible to have the portfolio item featured image to be automatic scaled up or down to fit in to screen size? To avoid need for scrolling to see th whole picture[deleted] repliedJanuary 22, 2019 at 8:39amHi Per,I understand your issue, here I have created a code only for your purpose: <script> jQuery( document ).ready( function() { var $featured = jQuery( '.single-portfolio .portfolio-featured-image' ), width = $featured.width(), height = $featured.height(), winWidth = jQuery( window ).width(), winHeight = jQuery( window ).height(); if ( $featured.length === 0 ) { return; } var excessiveHeight = winHeight - height; if ( excessiveHeight < 0 ) { var headerHeight = jQuery( '.site-header' ).outerHeight(); // Uncomment below line if you don't want to include header in viewport calculation (the image will be bigger) //headerHeight = 0; var newHeight = height + excessiveHeight - headerHeight, newWidth = width * ( newHeight / height ); $featured.css( { maxWidth: newWidth, marginLeft: 'auto', marginRight: 'auto' } ); } } ); </script> So here is demonstration how it works:https://d.pr/v/Vx0hpMTo add the code to your site go to Theme Options > Footer > JavaScript & Tracking Code > Footer JavaScript1 Like Per replied privately[deleted] repliedJanuary 23, 2019 at 8:01amHi Per, Glad to hear that Will set this ticket as solved from here. Per replied privately[deleted] repliedFebruary 4, 2019 at 10:02amHi Per,Sure you can modify the previous code to use the extra selector for blog posts as well:.single-post .post-image .featured-imageSo the final code would be: <script> jQuery( document ).ready( function() { var $featured = jQuery( '.single-portfolio .portfolio-featured-image, .single-post .post-image .featured-image' ), width = $featured.width(), height = $featured.height(), winWidth = jQuery( window ).width(), winHeight = jQuery( window ).height(); if ( $featured.length === 0 ) { return; } var excessiveHeight = winHeight - height; if ( excessiveHeight < 0 ) { var headerHeight = jQuery( '.site-header' ).outerHeight(); // Uncomment below line if you don't want to include header in viewport calculation (the image will be bigger) //headerHeight = 0; var newHeight = height + excessiveHeight - headerHeight, newWidth = width * ( newHeight / height ); $featured.css( { maxWidth: newWidth, marginLeft: 'auto', marginRight: 'auto' } ); } } ); </script> Sign in to reply ...
Hello,
Is it possible to have the portfolio item featured image to be automatic scaled up or down to fit in to screen size? To avoid need for scrolling to see th whole picture
Hi Per,
I understand your issue, here I have created a code only for your purpose:
So here is demonstration how it works:https://d.pr/v/Vx0hpM
To add the code to your site go to Theme Options > Footer > JavaScript & Tracking Code > Footer JavaScript
Hi Per,
Glad to hear that
Will set this ticket as solved from here.
Hi Per,
Sure you can modify the previous code to use the extra selector for blog posts as well:
.single-post .post-image .featured-image
So the final code would be: