Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery Accordion - will it scroll to the top of the open item?

With the jQuery accordion control, how can I have it scroll to an item I've selected when it is off the screen?

When:

  • I have an accordion item with contents larger than the viewable window
  • I scroll down to the second accordion item
  • I click the second accordion item to display it
  • The first accordion option collapses, and the second opens, but slides off screen.

Is there an option for the accordion to scroll to the second item?

like image 693
y0mbo Avatar asked Sep 01 '10 18:09

y0mbo


People also ask

How do I make my page scroll to the top in jQuery?

In jQuery, the scrollTo() method is used to set or return the vertical scrollbar position for a selected element. This behavior can be used to scroll to the top of the page by applying this method on the window property. Setting the position parameter to 0 scrolls the page to the top.

What does the jQuery accordion widget do?

jQuery - Widget accordion The Widget accordion function can be used with widgets in JqueryUI. Accordion is same like as Tabs,When user click headers to expand content that is broken into logical sections.

Which event is triggered when accordion is created?

The jQuery UI Accordion create event is used to trigger when the accordion is created. If an accordion widget is collapsed, then the ui.

How do you close an accordion when another jQuery opens?

Assuming you are using the jQuery UI accordion, you can collapse all sections with . accordion('activate', false) .

How to move the page to the scroll height of accordion?

2.accordion [0].scrollHeight - find the scroll height of the accordion that is opened. 3.Using the animate option using scrollTop the page is moved to the scroll height of the accordion. 4.To ensure step 2 & 3 are done after the accordion is open the setTimeout function is used to time the code after the accordion is open.

How to scroll to the top of the page using jQuery?

Before clicking the button: After clicking the button: Method 2: Using scrollTo() in jQuery. In jQuery, the scrollTo() method is used to set or return the vertical scrollbar position for a selected element.This behavior can be used to scroll to the top of the page by applying this method on the window property.

How to animate the accordion button?

1.An accordion variable is set to the parent node with class ".accordion" of the accordion button. 2.accordion [0].scrollHeight - find the scroll height of the accordion that is opened. 3.Using the animate option using scrollTop the page is moved to the scroll height of the accordion.

How to create a bootstrap accordion with JavaScript?

JavaScript Code: All you have to create a normal Bootstrap Accordion and paste the below JavaScript code int script tag then the action will begin. and REST API, you can not ignore JavaScript.


1 Answers

It works for me and tested,

$( "#accordion" ).accordion({     heightStyle: "content",     collapsible: true,     active: false,     activate: function( event, ui ) {         if(!$.isEmptyObject(ui.newHeader.offset())) {             $('html:not(:animated), body:not(:animated)').animate({ scrollTop: ui.newHeader.offset().top }, 'slow');         }     } }); 

http://jsfiddle.net/ilyasnone/aqw613em/

like image 60
iliyas Safi Avatar answered Sep 20 '22 15:09

iliyas Safi