Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Window edge detect #135

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions css/flexnav.css
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,16 @@
position: relative;
top: 1em;
color: #666; }

/* edge detect fix */
.flexnav li ul li.edge > ul {
left: auto;
right: 97%; }

.flexnav li.edge > ul {
left: auto;
right: 0; }
/* end edge detect */

@media all and (min-width: 800px) {
body.one-page {
Expand Down
32 changes: 30 additions & 2 deletions js/jquery.flexnav.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@
$ = jQuery;

$.fn.flexNav = function(options) {
var $nav, $top_nav_items, breakpoint, count, nav_percent, nav_width, resetMenu, resizer, settings, showMenu, toggle_selector, touch_selector;
var $nav, $top_nav_items, breakpoint, count, nav_percent, nav_width, resetMenu, resizer, settings, showMenu, toggle_selector, touch_selector, edgeDetect;
settings = $.extend({
'animationSpeed': 250,
'transitionOpacity': true,
'buttonSelector': '.menu-button',
'hoverIntent': false,
'hoverIntentTimeout': 150,
'calcItemWidths': false,
'hover': true
'hover': true,
'detectEdges': true
}, options);
$nav = $(this);
$nav.addClass('with-js');
Expand All @@ -40,6 +41,33 @@
nav_width = 100 / count;
nav_percent = nav_width + "%";
}
/* Edge Detect */
if (settings.detectEdges === true) {
$(function () {

$('.item-with-ul').on('mouseenter mouseleave', function (e) {
var elm = $('ul:first', this);
var off = elm.offset();
var l = off.left;
var w = elm.width();
var docW = $(window).width();

var isEntirelyVisible = (l + w <= docW);

if (!isEntirelyVisible) {
$(this).addClass('edge');
} else {
$(this).delay(260).queue(function () {
$(this).removeClass('edge');
$(this).dequeue();
});
}
});


});
}
/* End Edge Detect */
if ($nav.data('breakpoint')) {
breakpoint = $nav.data('breakpoint');
}
Expand Down