Tagged: cornerstone
-
AuthorPosts
-
March 8, 2017 at 3:27 am #1398810
Hi there,
I used the responsive code from https://community.theme.co/forums/topic/make-columns-same-height-in-cornerstone/#post-314832 to get my columns to match each others height. The code works great and I love it but now I have a bit of an issue when it comes to scaling my browser window. Ofcourse a regular user won’t keep increasing and decreasing the size of their window but since I’m building the website, I am and probably so will others. What happens can be seen in the added screenshots. At first (img1), everything is a-ok, not a problem. When I scale the browser window, the text will be pushed to more lines than before. The columns won’t grow with the needed space to fit the text. When I refresh the browser, everything snaps right back into place but it won’t automatically do that. Is there a way to tweak the code so it will do the scaling without having to press the refresh-button?
Using all the latest versions of WP, X and Cornerstone btw…
Thanks in advance!
March 8, 2017 at 7:16 am #1399010HI There,
Greetings!
Thanks for writing in! To assist you with this issue, we’ll first need you to provide us with your URL. This is to ensure that we can provide you with a tailored answer to your situation. Once you have provided us with your URL, we will be happy to assist you with everything.
March 9, 2017 at 3:06 am #1400287This reply has been marked as private.March 9, 2017 at 3:23 am #1400296Hello There,
Thanks for providing the url. I could not see any columns on the page. It may be private and that is why I am not seeing it. Meanwhile, to have the same column heights within Cornerstone, please edit the page in Cornerstone, go to the settings tab, Settings > Custom JS and insert the following custom js code
(function($){ $(window).load(function($) { $(".x-section").each(function(index, el) { var max = 0; $(this).find(".x-column").each(function(index, el) { if( $(this).height() > max ){ max = $(this).height(); } }); $(this).find(".x-column").css('height', max); }); }); })(jQuery);
We would loved to know if this has work for you. Thank you.
March 9, 2017 at 4:41 am #1400371This reply has been marked as private.March 9, 2017 at 4:44 am #1400376The code I’m using for the page I sent you in private is this:
jQuery(function($) { function set_equal_height() { var highestBox = 0; $('#equalize1').children('.x-column.x-1-2').each(function () { if($(this).height() > highestBox) highestBox = $(this).height(); }); $('#equalize1').children('.x-column.x-1-2').height(highestBox); } $( document ).ready( set_equal_height ); $( window ).load( set_equal_height ); $( window ).resize( set_equal_height ); set_equal_height(); }); jQuery(function($) { function set_equal_height() { var highestBox = 0; $('#equalize2').children('.x-column.x-1-2').each(function () { if($(this).height() > highestBox) highestBox = $(this).height(); }); $('#equalize2').children('.x-column.x-1-2').height(highestBox); } $( document ).ready( set_equal_height ); $( window ).load( set_equal_height ); $( window ).resize( set_equal_height ); set_equal_height(); });
March 9, 2017 at 7:49 am #1400509Hi There,
Please update the code to this:
jQuery(function($) { function set_equal_height(sectionID) { var highestBox = 0; $(sectionID).children('.x-column.x-1-2').each(function () { $(this).css('height', '100%'); if($(this).height() > highestBox) highestBox = $(this).height(); }); $(sectionID).children('.x-column.x-1-2').height(highestBox); } $( document ).ready( function() {set_equal_height('#equalize1'); set_equal_height('#equalize2'); } ); $( window ).load( function() {set_equal_height('#equalize1'); set_equal_height('#equalize2'); } ); $( window ).resize( function() {set_equal_height('#equalize1'); set_equal_height('#equalize2'); } ); });
Since we already set the height, even on resize, it will still call this height we first set. Now on resize, we need to reset columns height to it’s default height 100% then recalculate the current height again. I did also, trimmed the code to just one function to make it clean. See implementation here:http://screencast-o-matic.com/watch/cbeQIm6xDd
Hope this helps.
March 13, 2017 at 11:35 am #1405095You, Lely, are a true hero(in)! It works, looks great! Just for my understanding of the trimmed function: if I had to add #equalize3 and #equalize4 the function would look like this right?
jQuery(function($) { function set_equal_height(sectionID) { var highestBox = 0; $(sectionID).children('.x-column.x-1-2').each(function () { $(this).css('height', '100%'); if($(this).height() > highestBox) highestBox = $(this).height(); }); $(sectionID).children('.x-column.x-1-2').height(highestBox); } $( document ).ready( function() {set_equal_height('#equalize1'); set_equal_height('#equalize2'); set_equal_height('#equalize3'); set_equal_height('#equalize4'); } ); $( window ).load( function() {set_equal_height('#equalize1'); set_equal_height('#equalize2'); set_equal_height('#equalize3'); set_equal_height('#equalize4'); } ); $( window ).resize( function() {set_equal_height('#equalize1'); set_equal_height('#equalize2'); set_equal_height('#equalize3'); set_equal_height('#equalize4'); } ); });
Thank you very much for your help!
March 13, 2017 at 12:27 pm #1405146If you need anything else please let us know.
March 16, 2017 at 9:32 am #1409642Just one more thing: I have quite a few pages using this function and the amount of “#equalize..” differs per page. Sometimes one, sometimes 2 etc. On every page I put the function in the custom js. Is there a way to put the function in functions.php once so it can be used on all the pages?
March 16, 2017 at 12:36 pm #1409899Hi There,
Please try adding the code on Appereance > Customizer > Custom > Javascript.
Let us know how it goes,
joao
March 17, 2017 at 11:00 am #1411160I don’t appear to get any errors in my console and at the front-end everything looks great, so I take it’s working fine. Thanks!
March 17, 2017 at 3:25 pm #1411442You’re most welcome.
-
AuthorPosts