Accordion to scroll to current open item

KMP

The below is a simple accordion call out I have used for some time. Some of the open items contain a lot of text and when another item is chosen I need it to scroll to the selected open item. I've tried several times with variations from other posts using scrollTo but have had no success. Any help would be greatly appreciated.

$(document).ready(function() {

//ACCORDION BUTTON ACTION (ON CLICK DO THE FOLLOWING)
$('.turn1').click(function() {

    //REMOVE THE ON CLASS FROM ALL BUTTONS
    $('.turn1').removeClass('on');

    //NO MATTER WHAT WE CLOSE ALL OPEN SLIDES
    $('.turn2').slideUp('normal');

    //IF THE NEXT SLIDE WASN'T OPEN THEN OPEN IT
    if($(this).next().is(':hidden') == true) {

        //ADD THE ON CLASS TO THE BUTTON
        $(this).addClass('on');

        //OPEN THE SLIDE
        $(this).next().slideDown('normal');
     } 

 });

 $('.turn2').hide();
 $("#open").trigger('click');
 });

<script type="text/javascript">
$(function(){
    $('.turn1').click(function(){
        $.scrollTo(this)                                                 
    })
});
</script>

I also have this script which works nicely but having trouble with making the first accordion item to not jump down to the middle of the page where the first accordion item lives.

<script type="text/javascript">
$("#accord_holder").accordion({
autoHeight: false,
collapsible:true,
navigation:true,
active:false,
change: function(event, ui) {
    $(window).scrollTop(ui.newHeader.position().top - 1);
}
});
 </script>
Itay

Use jQuery's position and scrollTop():

<script type="text/javascript">
$(function(){
    $('.turn1').click(function(){
        $("html, body").scrollTop($(this).position().top);
    });
});
</script>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Deep link and open an accordion item

From Dev

Deep link and open an accordion item

From Dev

Bootstrap accordion, scroll to top of active (open) accordion on click?

From Dev

add "x" icon that hides the current open accordion

From Dev

Keep Jquery accordion menu open on current page

From Dev

Open first item in accordion on page load

From Dev

Let only 1 accordion item stay open

From Dev

Open List Item with Scroll Spy

From Dev

Open accordion menu items with sticky scroll menu links

From Dev

Open accordion panel from another page and scroll down to it

From Dev

Stop sliding up the current item on DC jQuery Vertical Accordion Menu

From Dev

AngularJS / ui-bootstrap accordion - scroll to top of active (open) accordion on click

From Dev

Open particular Jquery accordion pan based on current page URL

From Dev

How add "active" class to open Bootstrap 3 accordion item?

From Dev

Open Accordion Item Based on #target in URL - Wordpress Menu

From Dev

How add "active" class to open Bootstrap 3 accordion item?

From Dev

Accordion Menu: First menu item open on page load

From Dev

Accordion scroll issue - scroll to top of active accordion

From Dev

How can i scroll menu to current item in menu?

From Dev

Bootstrap Accordion - Closing other panels when the intend is to open it's current panel

From Dev

Close active accordion item

From Dev

Javascript - Accordion: how to let only one item to be open at any given time

From Dev

Bootstrap accordion open on hover

From Dev

Toggle open/close accordion

From Dev

Accordion toggle open/close

From Dev

Accordion Force Open Tab

From Dev

jquery Accordion open and close

From Dev

Bootstrap accordion open on hover

From Dev

First accordion panel open

Related Related

  1. 1

    Deep link and open an accordion item

  2. 2

    Deep link and open an accordion item

  3. 3

    Bootstrap accordion, scroll to top of active (open) accordion on click?

  4. 4

    add "x" icon that hides the current open accordion

  5. 5

    Keep Jquery accordion menu open on current page

  6. 6

    Open first item in accordion on page load

  7. 7

    Let only 1 accordion item stay open

  8. 8

    Open List Item with Scroll Spy

  9. 9

    Open accordion menu items with sticky scroll menu links

  10. 10

    Open accordion panel from another page and scroll down to it

  11. 11

    Stop sliding up the current item on DC jQuery Vertical Accordion Menu

  12. 12

    AngularJS / ui-bootstrap accordion - scroll to top of active (open) accordion on click

  13. 13

    Open particular Jquery accordion pan based on current page URL

  14. 14

    How add "active" class to open Bootstrap 3 accordion item?

  15. 15

    Open Accordion Item Based on #target in URL - Wordpress Menu

  16. 16

    How add "active" class to open Bootstrap 3 accordion item?

  17. 17

    Accordion Menu: First menu item open on page load

  18. 18

    Accordion scroll issue - scroll to top of active accordion

  19. 19

    How can i scroll menu to current item in menu?

  20. 20

    Bootstrap Accordion - Closing other panels when the intend is to open it's current panel

  21. 21

    Close active accordion item

  22. 22

    Javascript - Accordion: how to let only one item to be open at any given time

  23. 23

    Bootstrap accordion open on hover

  24. 24

    Toggle open/close accordion

  25. 25

    Accordion toggle open/close

  26. 26

    Accordion Force Open Tab

  27. 27

    jquery Accordion open and close

  28. 28

    Bootstrap accordion open on hover

  29. 29

    First accordion panel open

HotTag

Archive