Quantcast
Channel: DevExpress Support Center (Examples)
Viewing all articles
Browse latest Browse all 7205

ASPxNavBar - How to implement a table of contents with scrollable area

$
0
0

This example demonstrates how to implement a table of contents with the scrollable area using the ASPxNavBar control. An xml file is used as a data source here, however it is possible to do the same with any other data source.
The main idea is to add items both in ASPxNavBar and the scrollable area when you process an entry from the data source.

Once items are added, implement the function that will:
1) Determine an element that should be selected as an active item in the navbar:

[JScript]
var firstFullyVisibleIndex = 0; $(".section").each(function(){var scrollOffset = $(document).scrollTop();var elementOffset = $(this).offset().top;if(scrollOffset < elementOffset){ firstFullyVisibleIndex = $(this).index();returnfalse;}});
2) Select this item in the navbar:
[JScript]
if(selectedSectionIndex != firstFullyVisibleIndex){ selectedSectionIndex = firstFullyVisibleIndex;var group = navbar.GetActiveGroup();var newlySelectedItem = group.GetItem(selectedSectionIndex); navbar.SetSelectedItem(newlySelectedItem);}
Call this function in two event handlers: when the page loads and when the page is scrolled:
[JScript]
$(window).scroll(function(){ SyncNavbar();}); $().ready(function(){ navbar.SetActiveGroup(navbar.GetGroupByName(navbar.cpActiveGroup)); SyncNavbar();});

Viewing all articles
Browse latest Browse all 7205

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>