Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #919115

    Hi I have 3 images that should work as buttons. By clicking each one a specific section should show (by default they are not displayed) and the window should scroll at the beggining of the section (which has a unique id).

    I tried with the following code:

    function show_section(){
    ?>
    <script>
    jQuery(window).load(function(){
    jQuery( "#section" ).hide();
    jQuery( ".image" ).click(function() {
    jQuery( "#section" ).toggle();
    });
    });
    </script>
    <?php
    }
    add_action('wp_footer', 'show_section');

    This works fine, but the window does not scroll down to the section. How can I adjust the code in order to add the scrolling to the anchor text?

    Thabk you very much

    #919206

    I found the answer: just added the following script to the functions.php file (if somebody else is interested)

    function show_section(){
    ?>
    
    <script>
    jQuery(document).ready(function( $ ) {
    	$(".image").click(function(){
    		if ($('#section').css('display') == 'none') 
    		{
    			$("#section").css("display","block");
    		}
    		else
    		{
    			$("#section").css("display","none");
    		}
    		document.getElementById('diecimetri').scrollIntoView(true);	
    	});
    });
    </script>
    <?php
    }
    add_action('wp_footer', 'show_section');

    and then I added a css rule as follows

    #section {
    display:none;
    }
    #919429

    Hi,

    Great, glad you found a solution and thanks for sharing :-)

    Please let us know if you should need any further help on the topic or if we can close it.

    Best regards,
    Rikard

    #920482

    Yes please close it

    #920496

    Hi,

    If you need additional help, please let us know here in the forums.

    Best regards,
    Jordan Shannon

Viewing 5 posts - 1 through 5 (of 5 total)
  • The topic ‘toggle sections by clicking an image and sliding down to anchor text’ is closed to new replies.