Home
Dynamic Content
Flex Level Popup Menu
Supplementary Page
|
Categories
Other Sections
Sweet Ads
Compatibility
|
|
Dynamically applying flex menu to a linkA typical setup of Flex Menu calls for applying a flex menu to a
link by inserting the attribute <a href="http://www.dynamicdrive.com" data-popupmenu="flexmenu1">Dynamic Drive</a> where the attribute points to the ID of the flex menu on the page. This method of associating a menu with a link is static, and done when the page loads. You can also dynamically reference a link using the power of jQuery Selectors and apply a flex menu to it. The syntax is: $(elementselector).addpopupmenu('menuid') where " $('#myanchor').addpopupmenu('flexmenu1') //apply menu to link with ID="myanchor" $('.home').addpopupmenu('flexmenu1') //apply horizontal menu to links with class="home" $('#nav a').addpopupmenu('flexmenu1') //apply menu to links within the DIV with ID="nav" If you're setting up your links when the page loads, you'll need to call the above after the page has loaded, by wrapping it inside jQuery's DOM ready function for example: jQuery(document).ready(function($){ Dynamically defining your flex menu contentsYou can also define the HTML markup of your flex menus dynamically using JavaScript, so the menu contents are embedded inside a .js file. This is useful if multiple pages across your site all use the same flex menus, and you can't easily define the menus on each page as HTML markup. To do this, follow the below 3 steps: 1) Define your menu contents inside a .js file and using
the helper function
All this may seem a bit confusing, though simply study the structure of at flexpopupcontents.js for a little while, and a pattern should emerge as far as how to use this function. 2) Then on the pages that will use these menus, modify your page from the original set up of Flex Menu with the changes in red: <html>/ First, include a reference to your menu contents .js file (ie:popupmenu.js) in the HEAD section of your page following the core Flex Menu .js file. Then, append the menu to the page once the page has loaded by calling: $(document.body).append(flexmenuvar.menu) " $(elementselector).addpopupmenu('flexmenuid', options) where "" Here's the result: Dynamic Drive
Table Of ContentsThis script consists of an index page plus two supplementary pages:
|