KaiserEMP
10/17/2017 - 10:15 AM

NAV scroll on hover

    // submenu ----------------------------
	var box = $(".sub-navigation .subnav_container .subnav-menu"), x;
	$(".subnav_container .arrow").on('click mouseenter' , function() {
	  if ($(this).hasClass("subnav-right")) {
	    x = ((box.width() / 2)) + box.scrollLeft();
	    box.animate({
	      scrollLeft: x,
	    });
	  } else {
	    x = ((box.width() / 2)) - box.scrollLeft();
	    box.animate({
	      scrollLeft: -x,
	    });
	  }
	});

    $(".subnav-menu").on("scroll", function () {
        var cur = $(this).scrollLeft();
        if (cur === 0) {
            $('.subnav_container').addClass('shadow-right').removeClass('shadow-left');
        } 
        else {
            var max = $(this)[0].scrollWidth - $(this).parent().width();
            if (cur == max) {
                $('.subnav_container').addClass('shadow-left').removeClass('shadow-right');
            } else {
                $('.subnav_container').addClass('shadow-right shadow-left');
            }
        }
    });
    $(".subnav-menu").trigger("scroll");
    // ----------------------------

    checkSubWidth();
    function checkSubWidth() {
    	$('.subnav-menu').each(function(){
    		var elem = $(this);

    		var listWidth = 0;
    		$('.subnav-menu .menu-item').each(function() {
    		    listWidth += $(this).outerWidth( true );
				//console.log(listWidth);
    		});

			if($('.subnav-menu').outerWidth() > listWidth ){
				//console.log($('.subnav-menu').outerWidth());
				$('.subnav_container').removeClass('shadow-right');

			} else {
				$('.subnav_container').addClass('shadow-right');
			}
    	});
    }
    // ----------------------------