Advertisement
pixeline

Using superfish.js and Wordpress

Oct 31st, 2011
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // IMPROVE WORDPRESS DROPDOWN MAIN MENU WITH SOME DELAY, USING superfish.js JQUERY PLUGIN
  2.  
  3. // MAIN MENU FINETUNING
  4.     var maxWidth = $('#header').width() + $('#header').offset().left;
  5.     var menu, menuWidth, delta, menuLeft = 0;
  6.     $('#menu-main-menu').superfish({
  7.         autoArrows: false,
  8.         speed: 'fast',
  9.         hoverClass: 'selected-menu',
  10.         onInit: function() {
  11.             // Make sure the rightmost dropdown does not overflow the interface
  12.             $('#menu-main-menu ul.sub-menu').each(function(){
  13.                 menu = $(this);
  14.  
  15.                 menuWidth = menu.width();
  16.                
  17.                 menu.show(); // offset() does not work if element is hidden, so we show(), measure, then hide() it immediatly.
  18.                 menuLeft = menu.offset().left;
  19.                 menu.hide();
  20.                            
  21.                 delta = maxWidth - (menuLeft + menuWidth);
  22.                 if (delta < 0) {
  23.                     menuLeft = delta;
  24.                 } else {
  25.                     menuLeft = 0;
  26.                 }
  27.                 menu.css({
  28.                     left: menuLeft
  29.                 });
  30.             });
  31.         }
  32.     });
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement