Comments on: jQuery – Resize image to parent container plugin https://christianvarga.com/jquery-resize-image-to-parent-container-plugin/ Tue, 01 Nov 2022 01:12:58 +0000 hourly 1 https://wordpress.org/?v=6.6.2 By: Juan Mejía https://christianvarga.com/jquery-resize-image-to-parent-container-plugin/#comment-695 Mon, 12 Dec 2016 02:01:00 +0000 https://christianvarga.com/?p=30#comment-695 In reply to Christian Varga.

Chrome Versión 54.0.2840.98 on OSX Yosemite 10.10.05.
Christian, I really appreciate your time and your answers. I think i explained myself wrong. Anyway, i made the plugin work together with flexslider as you told me, setting the width and height (100vh, 100vw) to the flexslider and the image container. If the animation property of Flexslider is setted to “fade” works perfect and the setTimeOut function is not necessary. When i set it to “slide” the plugin needs the call wrapping in the setTimeOut function with at least 100 ms. Know it seams to work very well.

Thanks again Christian!

]]>
By: Christian Varga https://christianvarga.com/jquery-resize-image-to-parent-container-plugin/#comment-694 Mon, 12 Dec 2016 00:25:00 +0000 https://christianvarga.com/?p=30#comment-694 In reply to Juan Mejía.

When you say the code is miscalculating the width, are you talking about on your website, or the Codepen I provided? The Codepen works for me on Chrome 54.0.2840.98. If the Codepen doesn’t work for you, please let me know your browser and version, and also your operating system and version. If the Codepen works, then there’s a problem with your code. Delete all CSS that targets the slider, use my Codepen as an example, and start adding your CSS back in until it breaks. Then you’ll figure out what’s going on.

I added a 100ms timeout because the Flex Slider takes some time to initialise (I’m not going to investigate why). It has nothing to do with the loading time or size of the image. My plugin runs when the image has loaded by binding to the `load` event. So the size of the image or time taken to download has no effect on the operation of the plugin.

When you say “In case of loading new big images wont be reliable solution”, is that what you’ve actually experienced, or are you just making an assuming it won’t work? Because, again, my Codepen demonstrates that it does work, with both small and large images.

]]>
By: Juan Mejía https://christianvarga.com/jquery-resize-image-to-parent-container-plugin/#comment-693 Sun, 11 Dec 2016 14:39:00 +0000 https://christianvarga.com/?p=30#comment-693 In reply to Christian Varga.

Christian, Thanks for your quick reply!

Im using relative size for conteiner and slides (li) for full viewport withd and height. The timeout function works when the image was loaded before. In case of loading new big images wont be reliable solution 😔.

I see that the code is miscalculating the width of the image and the negative margin-left is not added. Is that because the css? Any ideas?

Thanks!!

]]>
By: Christian Varga https://christianvarga.com/jquery-resize-image-to-parent-container-plugin/#comment-692 Sun, 11 Dec 2016 03:14:00 +0000 https://christianvarga.com/?p=30#comment-692 In reply to Juan Mejía.

Hi Juan,

I’ve created a little test with Flex Slider, and I made it work by explicitly setting a height and width on both the flex slider wrapper and the slides themselves, and by wrapping the .resizeToParent() call in a timeout. It works as intended – both portrait and landscape images resize correctly. If it doesn’t work for you, chances are you have some CSS interfering with the resizing. Please check the following demo, then check your codebase to figure out what you’ve done different.

https://codepen.io/levymetal/pen/WoKmpb

]]>
By: Juan Mejía https://christianvarga.com/jquery-resize-image-to-parent-container-plugin/#comment-691 Sun, 11 Dec 2016 02:44:00 +0000 https://christianvarga.com/?p=30#comment-691 Hi Christian! thanks for your great work.
I am using FlexSlider and your plugin to create a full width and height background.
Im having problems when loading.
The image has ‘position:relative’.
On resize works perfect, but:
1. The image is not centering. On load align is always top – left. Also when the viewport height is greater than the width.
2. When the viewport is landscape, the width and the aspect ratio of the image is not correct and generates like a margin on the right. The size of the parent is correct.

Please help me to find a solution!
thanks in advance!

This is the web im working on “slumber.juanmejia.info/”

]]>
By: Владимир Антощенко https://christianvarga.com/jquery-resize-image-to-parent-container-plugin/#comment-688 Sat, 12 Nov 2016 15:31:00 +0000 https://christianvarga.com/?p=30#comment-688 Thanks Christian !!!

]]>
By: Christian Varga https://christianvarga.com/jquery-resize-image-to-parent-container-plugin/#comment-659 Tue, 17 May 2016 02:56:00 +0000 https://christianvarga.com/?p=30#comment-659 In reply to James.

Hi James, I haven’t built this into the plugin (interestingly enough no one has really asked for it!). However, you can apply a small tweak yourself which will achieve the result of ‘center bottom’. On line 52, simply change the -2 to -1, and the image will be positioned from the bottom. So line 52 would look like this:


var topOffset = (imageHeight - parentHeight) / -1;

Hope this helps

]]>
By: James https://christianvarga.com/jquery-resize-image-to-parent-container-plugin/#comment-658 Tue, 10 May 2016 22:16:00 +0000 https://christianvarga.com/?p=30#comment-658 Hi Christian

Thanks for this great plugin which has been perfect for my needs – and it’s working in responsive slideshows too which is brilliant.

I have a question – and I’m sorry if I’ve missed the answer somewhere else. Is it possible to position the images in their containing element as, for example, ‘bottom center’ rather than ‘center center’ – in the same way as background images can be positioned with CSS?

]]>
By: radin reth https://christianvarga.com/jquery-resize-image-to-parent-container-plugin/#comment-616 Tue, 14 Jul 2015 06:49:00 +0000 https://christianvarga.com/?p=30#comment-616 In reply to Christian Varga.

I mean misusing the library.

]]>
By: radin reth https://christianvarga.com/jquery-resize-image-to-parent-container-plugin/#comment-615 Tue, 14 Jul 2015 06:48:00 +0000 https://christianvarga.com/?p=30#comment-615 In reply to Christian Varga.

Hi Christian,

I got the problem fixed. It’s my fault in using the library,
Anyway Thanks you
Mr. non-magician 🙂

]]>
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" version="2.0">
<channel>
<title> Comments on: jQuery – Resize image to parent container plugin </title>
<atom:link href="https://christianvarga.com/jquery-resize-image-to-parent-container-plugin/feed/" rel="self" type="application/rss+xml"/>
<link>https://christianvarga.com/jquery-resize-image-to-parent-container-plugin/</link>
<description/>
<lastBuildDate>Tue, 01 Nov 2022 01:12:58 +0000</lastBuildDate>
<sy:updatePeriod> hourly </sy:updatePeriod>
<sy:updateFrequency> 1 </sy:updateFrequency>
<generator>https://wordpress.org/?v=6.6.2</generator>
<item>
<title> By: Juan Mejía </title>
<link>https://christianvarga.com/jquery-resize-image-to-parent-container-plugin/#comment-695</link>
<dc:creator>
<![CDATA[ Juan Mejía ]]>
</dc:creator>
<pubDate>Mon, 12 Dec 2016 02:01:00 +0000</pubDate>
<guid isPermaLink="false">https://christianvarga.com/?p=30#comment-695</guid>
<description>
<![CDATA[ In reply to &lt;a href=&quot;https://christianvarga.com/jquery-resize-image-to-parent-container-plugin/#comment-694&quot;&gt;Christian Varga&lt;/a&gt;. Chrome Versión 54.0.2840.98 on OSX Yosemite 10.10.05. Christian, I really appreciate your time and your answers. I think i explained myself wrong. Anyway, i made the plugin work together with flexslider as you told me, setting the width and height (100vh, 100vw) to the flexslider and the image container. If the animation property of Flexslider is setted to &quot;fade&quot; works perfect and the setTimeOut function is not necessary. When i set it to &quot;slide&quot; the plugin needs the call wrapping in the setTimeOut function with at least 100 ms. Know it seams to work very well. Thanks again Christian! ]]>
</description>
<content:encoded>
<![CDATA[ <p>In reply to <a href="https://christianvarga.com/jquery-resize-image-to-parent-container-plugin/#comment-694">Christian Varga</a>.</p> <p>Chrome Versión 54.0.2840.98 on OSX Yosemite 10.10.05.<br /> Christian, I really appreciate your time and your answers. I think i explained myself wrong. Anyway, i made the plugin work together with flexslider as you told me, setting the width and height (100vh, 100vw) to the flexslider and the image container. If the animation property of Flexslider is setted to &#8220;fade&#8221; works perfect and the setTimeOut function is not necessary. When i set it to &#8220;slide&#8221; the plugin needs the call wrapping in the setTimeOut function with at least 100 ms. Know it seams to work very well.</p> <p>Thanks again Christian!</p> ]]>
</content:encoded>
</item>
<item>
<title> By: Christian Varga </title>
<link>https://christianvarga.com/jquery-resize-image-to-parent-container-plugin/#comment-694</link>
<dc:creator>
<![CDATA[ Christian Varga ]]>
</dc:creator>
<pubDate>Mon, 12 Dec 2016 00:25:00 +0000</pubDate>
<guid isPermaLink="false">https://christianvarga.com/?p=30#comment-694</guid>
<description>
<![CDATA[ In reply to &lt;a href=&quot;https://christianvarga.com/jquery-resize-image-to-parent-container-plugin/#comment-693&quot;&gt;Juan Mejía&lt;/a&gt;. When you say the code is miscalculating the width, are you talking about on your website, or the Codepen I provided? The Codepen works for me on Chrome 54.0.2840.98. If the Codepen doesn&#039;t work for you, please let me know your browser and version, and also your operating system and version. If the Codepen works, then there&#039;s a problem with your code. Delete all CSS that targets the slider, use my Codepen as an example, and start adding your CSS back in until it breaks. Then you&#039;ll figure out what&#039;s going on. I added a 100ms timeout because the Flex Slider takes some time to initialise (I&#039;m not going to investigate why). It has nothing to do with the loading time or size of the image. My plugin runs when the image has loaded by binding to the `load` event. So the size of the image or time taken to download has no effect on the operation of the plugin. When you say &quot;In case of loading new big images wont be reliable solution&quot;, is that what you&#039;ve actually experienced, or are you just making an assuming it won&#039;t work? Because, again, my Codepen demonstrates that it does work, with both small and large images. ]]>
</description>
<content:encoded>
<![CDATA[ <p>In reply to <a href="https://christianvarga.com/jquery-resize-image-to-parent-container-plugin/#comment-693">Juan Mejía</a>.</p> <p>When you say the code is miscalculating the width, are you talking about on your website, or the Codepen I provided? The Codepen works for me on Chrome 54.0.2840.98. If the Codepen doesn&#8217;t work for you, please let me know your browser and version, and also your operating system and version. If the Codepen works, then there&#8217;s a problem with your code. Delete all CSS that targets the slider, use my Codepen as an example, and start adding your CSS back in until it breaks. Then you&#8217;ll figure out what&#8217;s going on.</p> <p>I added a 100ms timeout because the Flex Slider takes some time to initialise (I&#8217;m not going to investigate why). It has nothing to do with the loading time or size of the image. My plugin runs when the image has loaded by binding to the `load` event. So the size of the image or time taken to download has no effect on the operation of the plugin. </p> <p>When you say &#8220;In case of loading new big images wont be reliable solution&#8221;, is that what you&#8217;ve actually experienced, or are you just making an assuming it won&#8217;t work? Because, again, my Codepen demonstrates that it does work, with both small and large images.</p> ]]>
</content:encoded>
</item>
<item>
<title> By: Juan Mejía </title>
<link>https://christianvarga.com/jquery-resize-image-to-parent-container-plugin/#comment-693</link>
<dc:creator>
<![CDATA[ Juan Mejía ]]>
</dc:creator>
<pubDate>Sun, 11 Dec 2016 14:39:00 +0000</pubDate>
<guid isPermaLink="false">https://christianvarga.com/?p=30#comment-693</guid>
<description>
<![CDATA[ In reply to &lt;a href=&quot;https://christianvarga.com/jquery-resize-image-to-parent-container-plugin/#comment-692&quot;&gt;Christian Varga&lt;/a&gt;. Christian, Thanks for your quick reply! Im using relative size for conteiner and slides (li) for full viewport withd and height. The timeout function works when the image was loaded before. In case of loading new big images wont be reliable solution 😔. I see that the code is miscalculating the width of the image and the negative margin-left is not added. Is that because the css? Any ideas? Thanks!! ]]>
</description>
<content:encoded>
<![CDATA[ <p>In reply to <a href="https://christianvarga.com/jquery-resize-image-to-parent-container-plugin/#comment-692">Christian Varga</a>.</p> <p>Christian, Thanks for your quick reply!</p> <p>Im using relative size for conteiner and slides (li) for full viewport withd and height. The timeout function works when the image was loaded before. In case of loading new big images wont be reliable solution 😔.</p> <p>I see that the code is miscalculating the width of the image and the negative margin-left is not added. Is that because the css? Any ideas? </p> <p>Thanks!!</p> ]]>
</content:encoded>
</item>
<item>
<title> By: Christian Varga </title>
<link>https://christianvarga.com/jquery-resize-image-to-parent-container-plugin/#comment-692</link>
<dc:creator>
<![CDATA[ Christian Varga ]]>
</dc:creator>
<pubDate>Sun, 11 Dec 2016 03:14:00 +0000</pubDate>
<guid isPermaLink="false">https://christianvarga.com/?p=30#comment-692</guid>
<description>
<![CDATA[ In reply to &lt;a href=&quot;https://christianvarga.com/jquery-resize-image-to-parent-container-plugin/#comment-691&quot;&gt;Juan Mejía&lt;/a&gt;. Hi Juan, I&#039;ve created a little test with Flex Slider, and I made it work by explicitly setting a height and width on both the flex slider wrapper and the slides themselves, and by wrapping the .resizeToParent() call in a timeout. It works as intended - both portrait and landscape images resize correctly. If it doesn&#039;t work for you, chances are you have some CSS interfering with the resizing. Please check the following demo, then check your codebase to figure out what you&#039;ve done different. https://codepen.io/levymetal/pen/WoKmpb ]]>
</description>
<content:encoded>
<![CDATA[ <p>In reply to <a href="https://christianvarga.com/jquery-resize-image-to-parent-container-plugin/#comment-691">Juan Mejía</a>.</p> <p>Hi Juan,</p> <p>I&#8217;ve created a little test with Flex Slider, and I made it work by explicitly setting a height and width on both the flex slider wrapper and the slides themselves, and by wrapping the .resizeToParent() call in a timeout. It works as intended &#8211; both portrait and landscape images resize correctly. If it doesn&#8217;t work for you, chances are you have some CSS interfering with the resizing. Please check the following demo, then check your codebase to figure out what you&#8217;ve done different.</p> <p><a href="https://codepen.io/levymetal/pen/WoKmpb" rel="nofollow ugc">https://codepen.io/levymetal/pen/WoKmpb</a></p> ]]>
</content:encoded>
</item>
<item>
<title> By: Juan Mejía </title>
<link>https://christianvarga.com/jquery-resize-image-to-parent-container-plugin/#comment-691</link>
<dc:creator>
<![CDATA[ Juan Mejía ]]>
</dc:creator>
<pubDate>Sun, 11 Dec 2016 02:44:00 +0000</pubDate>
<guid isPermaLink="false">https://christianvarga.com/?p=30#comment-691</guid>
<description>
<![CDATA[ Hi Christian! thanks for your great work. I am using FlexSlider and your plugin to create a full width and height background. Im having problems when loading. The image has &#039;position:relative&#039;. On resize works perfect, but: 1. The image is not centering. On load align is always top - left. Also when the viewport height is greater than the width. 2. When the viewport is landscape, the width and the aspect ratio of the image is not correct and generates like a margin on the right. The size of the parent is correct. Please help me to find a solution! thanks in advance! This is the web im working on &quot;slumber.juanmejia.info/&quot; ]]>
</description>
<content:encoded>
<![CDATA[ <p>Hi Christian! thanks for your great work.<br /> I am using FlexSlider and your plugin to create a full width and height background.<br /> Im having problems when loading.<br /> The image has &#8216;position:relative&#8217;.<br /> On resize works perfect, but:<br /> 1. The image is not centering. On load align is always top &#8211; left. Also when the viewport height is greater than the width.<br /> 2. When the viewport is landscape, the width and the aspect ratio of the image is not correct and generates like a margin on the right. The size of the parent is correct.</p> <p>Please help me to find a solution!<br /> thanks in advance!</p> <p>This is the web im working on &#8220;slumber.juanmejia.info/&#8221;</p> ]]>
</content:encoded>
</item>
<item>
<title> By: Владимир Антощенко </title>
<link>https://christianvarga.com/jquery-resize-image-to-parent-container-plugin/#comment-688</link>
<dc:creator>
<![CDATA[ Владимир Антощенко ]]>
</dc:creator>
<pubDate>Sat, 12 Nov 2016 15:31:00 +0000</pubDate>
<guid isPermaLink="false">https://christianvarga.com/?p=30#comment-688</guid>
<description>
<![CDATA[ Thanks Christian !!! ]]>
</description>
<content:encoded>
<![CDATA[ <p>Thanks Christian !!!</p> ]]>
</content:encoded>
</item>
<item>
<title> By: Christian Varga </title>
<link>https://christianvarga.com/jquery-resize-image-to-parent-container-plugin/#comment-659</link>
<dc:creator>
<![CDATA[ Christian Varga ]]>
</dc:creator>
<pubDate>Tue, 17 May 2016 02:56:00 +0000</pubDate>
<guid isPermaLink="false">https://christianvarga.com/?p=30#comment-659</guid>
<description>
<![CDATA[ In reply to &lt;a href=&quot;https://christianvarga.com/jquery-resize-image-to-parent-container-plugin/#comment-658&quot;&gt;James&lt;/a&gt;. Hi James, I haven&#039;t built this into the plugin (interestingly enough no one has really asked for it!). However, you can apply a small tweak yourself which will achieve the result of &#039;center bottom&#039;. On line 52, simply change the -2 to -1, and the image will be positioned from the bottom. So line 52 would look like this: &lt;code&gt; var topOffset = (imageHeight - parentHeight) / -1; &lt;/code&gt; Hope this helps ]]>
</description>
<content:encoded>
<![CDATA[ <p>In reply to <a href="https://christianvarga.com/jquery-resize-image-to-parent-container-plugin/#comment-658">James</a>.</p> <p>Hi James, I haven&#8217;t built this into the plugin (interestingly enough no one has really asked for it!). However, you can apply a small tweak yourself which will achieve the result of &#8216;center bottom&#8217;. On line 52, simply change the -2 to -1, and the image will be positioned from the bottom. So line 52 would look like this: </p> <p><code><br /> var topOffset = (imageHeight - parentHeight) / -1;<br /> </code></p> <p>Hope this helps</p> ]]>
</content:encoded>
</item>
<item>
<title> By: James </title>
<link>https://christianvarga.com/jquery-resize-image-to-parent-container-plugin/#comment-658</link>
<dc:creator>
<![CDATA[ James ]]>
</dc:creator>
<pubDate>Tue, 10 May 2016 22:16:00 +0000</pubDate>
<guid isPermaLink="false">https://christianvarga.com/?p=30#comment-658</guid>
<description>
<![CDATA[ Hi Christian Thanks for this great plugin which has been perfect for my needs - and it&#039;s working in responsive slideshows too which is brilliant. I have a question - and I&#039;m sorry if I&#039;ve missed the answer somewhere else. Is it possible to position the images in their containing element as, for example, &#039;bottom center&#039; rather than &#039;center center&#039; - in the same way as background images can be positioned with CSS? ]]>
</description>
<content:encoded>
<![CDATA[ <p>Hi Christian</p> <p>Thanks for this great plugin which has been perfect for my needs &#8211; and it&#8217;s working in responsive slideshows too which is brilliant.</p> <p>I have a question &#8211; and I&#8217;m sorry if I&#8217;ve missed the answer somewhere else. Is it possible to position the images in their containing element as, for example, &#8216;bottom center&#8217; rather than &#8216;center center&#8217; &#8211; in the same way as background images can be positioned with CSS?</p> ]]>
</content:encoded>
</item>
<item>
<title> By: radin reth </title>
<link>https://christianvarga.com/jquery-resize-image-to-parent-container-plugin/#comment-616</link>
<dc:creator>
<![CDATA[ radin reth ]]>
</dc:creator>
<pubDate>Tue, 14 Jul 2015 06:49:00 +0000</pubDate>
<guid isPermaLink="false">https://christianvarga.com/?p=30#comment-616</guid>
<description>
<![CDATA[ In reply to &lt;a href=&quot;https://christianvarga.com/jquery-resize-image-to-parent-container-plugin/#comment-614&quot;&gt;Christian Varga&lt;/a&gt;. I mean misusing the library. ]]>
</description>
<content:encoded>
<![CDATA[ <p>In reply to <a href="https://christianvarga.com/jquery-resize-image-to-parent-container-plugin/#comment-614">Christian Varga</a>.</p> <p>I mean misusing the library.</p> ]]>
</content:encoded>
</item>
<item>
<title> By: radin reth </title>
<link>https://christianvarga.com/jquery-resize-image-to-parent-container-plugin/#comment-615</link>
<dc:creator>
<![CDATA[ radin reth ]]>
</dc:creator>
<pubDate>Tue, 14 Jul 2015 06:48:00 +0000</pubDate>
<guid isPermaLink="false">https://christianvarga.com/?p=30#comment-615</guid>
<description>
<![CDATA[ In reply to &lt;a href=&quot;https://christianvarga.com/jquery-resize-image-to-parent-container-plugin/#comment-614&quot;&gt;Christian Varga&lt;/a&gt;. Hi Christian, I got the problem fixed. It&#039;s my fault in using the library, Anyway Thanks you Mr. non-magician :) ]]>
</description>
<content:encoded>
<![CDATA[ <p>In reply to <a href="https://christianvarga.com/jquery-resize-image-to-parent-container-plugin/#comment-614">Christian Varga</a>.</p> <p>Hi Christian,</p> <p>I got the problem fixed. It&#8217;s my fault in using the library,<br /> Anyway Thanks you<br /> Mr. non-magician 🙂</p> ]]>
</content:encoded>
</item>
</channel>
</rss>