Tagged: x
-
AuthorPosts
-
October 14, 2016 at 12:54 am #1215758
chrispaynterdeependParticipantHi, I’m trying to make a mobile site where buttons control which section of content is displayed.
I have found javascript on the Themeco forum that allows a button to show/hide a section when clicked, however I can’t find info on how to setup button clicks to open one section and close all other visible sections.
My problem at the moment is that if I click all four buttons on the page, all 4 sections remain open. I only want to ever display 1 section of content (other than the header and buttons).
I have made a demo of what I’m trying to do here: http://care4.org.au/testmobile/ . Password is ‘duncan’.
Thank you in advance!
October 14, 2016 at 1:36 am #1215792
RupokMemberHey there,
Thanks for writing in! Regretfully, this particular customization request is outside the scope of our support as this is not related to an issue with the theme and instead has to do with your customization of it. As such, you will need to investigate this particular issue on your own or seek help from a developer should you not feel comfortable making these changes yourself. If you have any further questions about the theme, we are more than happy to provide you with assistance on these inquiries.
Thank you for your understanding.
October 19, 2016 at 12:33 am #1221849
chrispaynterdeependParticipantHi, I am following instructions from the forum in this thread:
The only code not discussed is something to ‘roll up’ all visible sections when a button is pushed. Can you advise if there is relatively simple JS that could be added to perform this task?
October 19, 2016 at 5:06 am #1222050
LelyModeratorHi There,
Would you mind providing us with login credentials so we can take a closer look on your current custom javacript? To do this, you can make a post with the following info:
– Link to your site
– WordPress Admin username / passwordDon’t forget to select Set as private reply. This ensures your information is only visible to our staff.
October 19, 2016 at 6:48 pm #1223010
chrispaynterdeependParticipantThis reply has been marked as private.October 20, 2016 at 1:28 am #1223422
LelyModeratorHi There,
Please update your javascript code to this:
jQuery(document).ready(function($){ // 1. On load quickly grab the natural height of the section var sectionExpandableHeight = $('#triggersection1.x-section.rolldown').height(); // 2. Then set it to be small like 10px height $('#triggersection1.x-section.rolldown').css('height','10px'); // 3. Give the button a class to identify the section's closed state $('#triggerbutton1').addClass('closed'); // 4. When the button is clicked... $('#triggerbutton1.closed').click(function(){ // Close other open section $(".rolldown:not(#triggersection1)").each(function( index ) { if($(this).css('display') == 'block'){ $(this).slideToggle(500); } }); // 5. Animate the expansion of the section $('#triggersection1.x-section.rolldown').animate({height: sectionExpandableHeight}, 500, function () { // 6. Upon completion set the height back to auto to accomodate anything dynamic inside $(this).css('height','auto'); }); // 7. Give the button the right state by removing closed and adding open $('#triggerbutton1').removeClass('closed'); $('#triggerbutton1').addClass('open'); return false; }); }); // 8. Now for the section to roll back up jQuery(document).ready(function($){ $('#triggersection1.rolldown').slideToggle(0); $('#triggerbutton1').on('touchend click', function(){ $('#triggersection1.rolldown').slideToggle( "slow" ); }); }); jQuery(document).ready(function($){ // 1. On load quickly grab the natural height of the section var sectionExpandableHeight = $('#triggersection2.x-section.rolldown').height(); // 2. Then set it to be small like 10px height $('#triggersection2.x-section.rolldown').css('height','10px'); // 3. Give the button a class to identify the section's closed state $('#triggerbutton2').addClass('closed'); // 4. When the button is clicked... $('#triggerbutton2.closed').click(function(){ // Close other open section $(".rolldown:not(#triggersection2)").each(function( index ) { if($(this).css('display') == 'block'){ $(this).slideToggle(500); } }); // 5. Animate the expansion of the section $('#triggersection2.x-section.rolldown').animate({height: sectionExpandableHeight}, 500, function () { // 6. Upon completion set the height back to auto to accomodate anything dynamic inside $(this).css('height','auto'); }); // 7. Give the button the right state by removing closed and adding open $('#triggerbutton2').removeClass('closed'); $('#triggerbutton2').addClass('open'); return false; }); }); jQuery(document).ready(function($){ $('#triggersection2.rolldown').slideToggle(0); $('#triggerbutton2').on('touchend click', function(){ $('#triggersection2.rolldown').slideToggle( "slow" ); }); }); jQuery(document).ready(function($){ // 1. On load quickly grab the natural height of the section var sectionExpandableHeight = $('#triggersection3.x-section.rolldown').height(); // 2. Then set it to be small like 10px height $('#triggersection3.x-section.rolldown').css('height','10px'); // 3. Give the button a class to identify the section's closed state $('#triggerbutton3').addClass('closed'); // 4. When the button is clicked... $('#triggerbutton3.closed').click(function(){ // Close other open section $(".rolldown:not(#triggersection3)").each(function( index ) { if($(this).css('display') == 'block'){ $(this).slideToggle(500); } }); // 5. Animate the expansion of the section $('#triggersection3.x-section.rolldown').animate({height: sectionExpandableHeight}, 500, function () { // 6. Upon completion set the height back to auto to accomodate anything dynamic inside $(this).css('height','auto'); }); // 7. Give the button the right state by removing closed and adding open $('#triggerbutton3').removeClass('closed'); $('#triggerbutton3').addClass('open'); return false; }); }); jQuery(document).ready(function($){ $('#triggersection3.rolldown').slideToggle(0); $('#triggerbutton3').on('touchend click', function(){ $('#triggersection3.rolldown').slideToggle( "slow" ); }); }); jQuery(document).ready(function($){ // 1. On load quickly grab the natural height of the section var sectionExpandableHeight = $('#triggersection4.x-section.rolldown').height(); // 2. Then set it to be small like 10px height $('#triggersection4.x-section.rolldown').css('height','10px'); // 3. Give the button a class to identify the section's closed state $('#triggerbutton4').addClass('closed'); // 4. When the button is clicked... $('#triggerbutton4.closed').click(function(){ // Close other open section $(".rolldown:not(#triggersection4)").each(function( index ) { if($(this).css('display') == 'block'){ $(this).slideToggle(500); } }); // 5. Animate the expansion of the section $('#triggersection4.x-section.rolldown').animate({height: sectionExpandableHeight}, 500, function () { // 6. Upon completion set the height back to auto to accomodate anything dynamic inside $(this).css('height','auto'); }); // 7. Give the button the right state by removing closed and adding open $('#triggerbutton4').removeClass('closed'); $('#triggerbutton4').addClass('open'); return false; }); }); jQuery(document).ready(function($){ $('#triggersection4.rolldown').slideToggle(0); $('#triggerbutton4').on('touchend click', function(){ $('#triggersection4.rolldown').slideToggle( "slow" ); }); });Hope this helps.
October 20, 2016 at 1:54 am #1223464
chrispaynterdeependParticipantThank you for your suggestion!
I just tried this code (using Safari on an iPhone to test). When pushing the button, the section rolls down and then in a second or so rolls back up again automatically, rather than stay open until another button is pushed (which would roll up the open section, and roll down the section associated to the button).
October 20, 2016 at 2:26 am #1223492
LelyModeratorHi There,
Please try remove this part first:
jQuery(document).ready(function($){ $('#triggersection4.rolldown').slideToggle(0); $('#triggerbutton4').on('touchend click', function(){ $('#triggersection4.rolldown').slideToggle( "slow" ); }); });Then try clearing browser cache on mobile and try again. Do let us know how this goes.
October 20, 2016 at 10:43 pm #1224906
chrispaynterdeependParticipantSo close!
That change is making it work exactly the way I want it to on desktop (chrome), however on multiple mobile devices (safari/chrome) it rolls down on button press and then rolls straight back up automatically.
Any suggestions?
October 20, 2016 at 10:59 pm #1224917
morecolorParticipanttry collapseomatic
October 21, 2016 at 1:48 am #1225058
RadModeratorThanks for sharing @Morecolor
@Chris try removing all instances of that similar code ( from #1223492 ), there are multiple copies of them with just different ID.
Thanks!
-
AuthorPosts
- <script> jQuery(function($){ $("#no-reply-1215758 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>
