Forum Replies Created

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • in reply to: Toggle a section when a button is clicked #1267819

    Thanks Ismael, it’s ok now. here is the final code :

    //-------------------------------
    // Toggle section
    //-------------------------------
    
    function toggle_on_click(){
    ?>
    <script>
    	
    jQuery(window).load(function(){	
    
    // Button onClick event
    
    jQuery(".toggle-button a").on("click", function() {
    
    	
    	// Add your button events here
    
    	console.log("toggle section");
    
    jQuery( "#toggle-section" ).animate({
        opacity: 1,
        height: "toggle"
      }, 1500, function() {
        // Animation complete.
      });
    
    	console.log("Prevent default");
    
    	e.preventDefault();
    
    });
    
    });
    </script>
    <?php
    }
    add_action('wp_footer', 'toggle_on_click');
    
    function add_custom_href_remove(){
    ?>
    <script>
    jQuery(window).load(function(){
    jQuery('.toggle-button a').removeAttr('href');
    });
    </script>
    <?php
    }
    add_action('wp_footer', 'add_custom_href_remove');
    in reply to: Toggle a section when a button is clicked #1267200

    where can i had this function ? for the moment i have this in functions.php:

    //——————————-
    // Toggle section
    //——————————-

    function toggle_on_click(){
    ?>
    <script>

    jQuery(window).load(function(){

    // Button onClick event

    jQuery(“.toggle-button a”).on(“click”, function() {

    // Add your button events here

    console.log(“toggle section”);

    jQuery(“#toggle-section”).toggleClass(“hide-me”);

    console.log(“Prevent default”);

    e.preventDefault();

    });

    });
    </script>
    <?php
    }
    add_action(‘wp_footer’, ‘toggle_on_click’);

    function add_custom_href_remove(){
    ?>
    <script>
    jQuery(window).load(function(){
    jQuery(‘.toggle-button a’).removeAttr(‘href’);
    });
    </script>
    <?php
    }
    add_action(‘wp_footer’, ‘add_custom_href_remove’);

    in reply to: Toggle a section when a button is clicked #1266309

    jQuery(“.toggle-button a”).on(“click”, function(e) {
    replaced by
    jQuery(“.toggle-button a”).on(“click”, function() {
    work now

    Is there a way to animate the opening and closing of the section so that the transition is less ‘abrupt’?

    • This reply was modified 3 years, 11 months ago by Anna.
Viewing 3 posts - 1 through 3 (of 3 total)