I have a div called #slideshow
that contains images with a 2:1 aspect ratio. To set the height of the image using jQuery, I use the following function:
Keep in mind that the Slideshow Div is always 100% wide in relation to the browser window. If the user resizes the window, the slideshow will adjust accordingly.
slideWidth();
function slideWidth(){
var width = $("#slideshow").css("width");
var height = (parseInt(width.substr(0,width.length-2)) / 3);
$("#slideshow").css("height", height + "px");
}
In order to dynamically change the width, I utilize the setTimeout function like so:
setInterval(slideWidth, 1000);
This method is working as intended. However, I am concerned about the impact it may have on the website performance due to constantly refreshing the slidewidth
function every second.
Is there a way to achieve this using CSS3 or with jQuery/JavaScript while minimizing the impact on the website?
Thank you. Please share any new ideas or suggestions you may have.