Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Advanced Search
  • 0

how to toggle show/hide text above as well as below


fuzzypyro

Question

I am trying to create an acceptance button using the code provided below. I can not figure out how to hide the text above when the text below is shown. I know there are much easier ways to make an acceptance button but this is just how I wanna do mine. Any help on the topic would be greatly appreciated. I honestly don't even know what language this is to be exact. It looks like javascript to me but my friend tells me its not.

 

<script>
 /* This script is a custom script to control the 'show' / 'hide' extra feature.  
 To use: give each button you want to make an expander an href of "expand-3", if you want it to expand / collapse the next 3 blocks.

 Make sure to make each button say 'Show More' as its default text.
 */

 var SHOW_MORE = 'I Accept'
 var COLLAPSE = 'Show Agreement'
 $(window).load(function(){
   // prepares all buttons by wrapping the correct # of following divs into a div with class 'extra_gallery'
   $('a[href^="#expand"]').each(function(){
     // parse # of sibling elements to wrap from href attribute and then wrap them.
     var n = parseInt($(this).attr('href').split('-')[1]);
     var next_n_divs = $(this).parents('div.sqs-block').nextAll().slice(0,n)
     // this is the line that is different.  we use display:none; on the DOM element that wraps the additional gallery.
     next_n_divs.wrapAll('<div class="extra-gallery" style="display:none;"></div>');
/*      // preload_images
     next_n_divs.find('img').each(function(){
       image = new Image();
       image.src = $(this).attr('data-src')+'?format=500w';
       console.log($(this).attr('data-src'));
     });
     // control for click behavior
     */
     $(this).click(function(){
       var target_gallery = $(this).parents('div.sqs-block').next('div.extra-gallery')
       if (target_gallery.is(':visible')){
         $(this).text(SHOW_MORE);
       }
       else {
         $(this).text(COLLAPSE);
       }
       target_gallery.slideToggle();
       return false;
     });
   });
 });
</script>

Edited by fuzzypyro
Link to post
  • Answers 3
  • Created
  • Last Reply

Top Posters For This Question

Popular Days

Top Posters For This Question

Posted Images

3 answers to this question

Recommended Posts

  • 0

Could you show us the current page that uses the code? or at least the name of the template

Greeting, it's BaNgan from BeyondSpace, I am Squarespace dev focus on provide solutions to enhance feature that squarespace.com can't provide.
Feel free to check my current Squarespace Plugins Developement, Advanced Product Delivery Date Time PickerGeolocation Automatic Currency Converter, Sortable Table from GSheet
If you find my answer fit your need, let's leave a like or upvote so others with the same issue can find their solution. Thank you

Link to post
  • 0
  • 0

Hi there

i need to check your site to tweak the script to correct, you may want to enable temp password so I can have a look

Greeting, it's BaNgan from BeyondSpace, I am Squarespace dev focus on provide solutions to enhance feature that squarespace.com can't provide.
Feel free to check my current Squarespace Plugins Developement, Advanced Product Delivery Date Time PickerGeolocation Automatic Currency Converter, Sortable Table from GSheet
If you find my answer fit your need, let's leave a like or upvote so others with the same issue can find their solution. Thank you

Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment


×
×
  • Create New...