I'm using a template. I have implemented flexslider twice in a page. But after that I'm having a issue with scrollspy. I have tried every solutions I've found here or on the web, but no luck yet. The issue is when i select the "mission" from navigation menu, it will be scrolled to appropriate section, but the previous button "technology" gets activated and highlighted. Same applies to other sections too. and when you manually scroll a bit further after clicking mission, it will be activated. You can see the issue Here
I have tried changing the offset value and the height of flexslider (technology section here) in following code. Can anyone help with this? The version of FlexSlider is v2.2.0
function ScrollSpy(element, options) {
var href;
var process = $.proxy(this.process, this);
this.$element = $(element).is('body') ? $(window) : $(element);
this.$body = $('body');
this.$scrollElement = this.$element.on('scroll.bs.scroll-spy.data-api', process);
this.options = $.extend({}, ScrollSpy.DEFAULTS, options);
this.selector = (this.options.target || ((href = $(element).attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')) || '') + ' > ul > li > a';
this.offsets = $([]);
this.targets = $([]);
this.activeTarget = null;
this.refresh();
this.process();
}
ScrollSpy.DEFAULTS = {
offset: 30
}
ScrollSpy.prototype.refresh = function () {
var offsetMethod = this.$element[0] == window ? 'offset' : 'position';
this.offsets = $([]);
this.targets = $([]);
var self = this;
var $targets = this.$body.find(this.selector).map(function () {
var $el = $(this);
var href = $el.data('target') || $el.attr('href');
var $href = /^#\w/.test(href) && $(href);
return ($href && $href.length && [[ $href[offsetMethod]().top + (!$.isWindow(self.$scrollElement.get(0)) && self.$scrollElement.scrollTop()), href ]]) || null
}).sort(function (a, b) {
return a[0] - b[0]
}).each(function () {
self.offsets.push(this[0]);
self.targets.push(this[1]);
});
}
ScrollSpy.prototype.process = function () {
var scrollTop = this.$scrollElement.scrollTop() + this.options.offset,
scrollHeight = this.$scrollElement[0].scrollHeight || this.$body[0].scrollHeight,
maxScroll = scrollHeight - this.$scrollElement.height(),
offsets = this.offsets,
targets = this.targets,
activeTarget = this.activeTarget, i;
if (scrollTop >= maxScroll) {
return activeTarget != (i = targets.last()[0]) && this.activate(i);
}
for (i = offsets.length; i--;) {
activeTarget != targets[i] && scrollTop >= offsets[i] && (!offsets[i + 1] || scrollTop <= offsets[i + 1]) && this.activate( targets[i] );
}
}
ScrollSpy.prototype.activate = function (target) {
this.activeTarget = target;
$(this.selector).parent('li').removeClass('current-menu-item');
var selector = this.selector + '[data-target="' + target + '"],' + this.selector + '[href="' + target + '"]';
var active = $(selector).parents('li').addClass('current-menu-item');
active.trigger('activate');
}
// SCROLLSPY PLUGIN DEFINITION
// ===========================
$.fn.scrollspy = function (option) {
return this.each(function () {
var $this = $(this),
data = $this.data('bs.scrollspy'),
options = typeof option == 'object' && option;
if (!data) {
$this.data('bs.scrollspy', (data = new ScrollSpy(this, options)));
}
if (typeof option == 'string') { data[option](); }
});
}
$.fn.scrollspy.Constructor = ScrollSpy;