<div id="selector" class="navbar navbar-default">
ul class="nav navbar-nav"li><a href="#one">one</a> ="#two">two="#three">threeul>
divdata-spy="scroll" data-target="#selector" style="height:100px; overflow:hidden;overflow-y: auto;" h4 ="one" >ibeh4p>One的具体内容br/>One的具体内容/></="two" ="three" >
function ScrollSpy(element,options) {
this.$body = $(document.body)
this.$scrollElement = $(element).is(document.body) ? $(window) : $(element)
this.options = $.extend({},ScrollSpy.DEFAULTS,options)
this.selector = (this.options.target || '') + ' .nav li > a'
this.offsets = []
this.targets =this.activeTarget = null
this.scrollHeight = 0
this.$scrollElement.on('scroll.bs.scrollspy',$.proxy(this.process,this))
.refresh()
.process()
}
this.$scrollElement[0].scrollHeight || Math.max(this.$body[0].scrollHeight,document.documentElement.scrollHeight)
ScrollSpy.prototype.refresh = () {
var that = this
var offsetMethod = 'offset'
var offsetBase = 0
this.offsets =this.targets =this.scrollHeight = .getScrollHeight()
if (!$.isWindow(this.$scrollElement[0])) {
offsetMethod = 'position'
offsetBase = .$scrollElement.scrollTop()
}
.$body
.find(.selector)
.map( () {
var $el = $()
var href = $el.data('target') || $el.attr('href'var $href = /^#./.test(href) && $(href)
return ($href
&& $href.length
&& $href.is(':visible')
&& [[$href[offsetMethod]().top + offsetBase,href]]) || null
})
.sort(function (a,b) { return a[0] - b[0] })
.each( () {
that.offsets.push(this[0])
that.targets.push(this[1])
})
}
.$scrollElement.scrollTop()
}
ScrollSpy.prototype.process = var scrollTop = this.$scrollElement.scrollTop() + .options.offset
var scrollHeight = .getScrollHeight()
var maxScroll = this.options.offset + scrollHeight - .$scrollElement.height()
var offsets = .offsets
var targets = .targets
var activeTarget = .activeTarget
var i
if (this.scrollHeight != scrollHeight) {
.refresh()
}
if (scrollTop >= maxScroll) {
return activeTarget != (i = targets[targets.length - 1]) && .activate(i)
}
if (activeTarget && scrollTop < offsets[0]) {
this.activeTarget = null
return .clear()
}
for (i = offsets.length; i--;) {
activeTarget != targets[i]
&& scrollTop >= offsets[i]
&& (offsets[i + 1] === undefined || scrollTop < offsets[i + 1])
&& .activate(targets[i])
}
}
this.$scrollElement.height()
ScrollSpy.prototype.activate = (target) {
this.activeTarget = target
.clear()
var selector = this.selector +
'[data-target="' + target + '"],' +
this.selector + '[href="' + target + '"]'
var active = $(selector)
.parents('li')
.addClass('active')
if (active.parent('.dropdown-menu').length) {
active = active
.closest('li.dropdown')
.addClass('active')
}
active.trigger('activate.bs.scrollspy')
}
ScrollSpy.prototype.clear = () {
$(.selector)
.parentsUntil(this.options.target,'.active')
.removeClass('active')
}
+ ($) {
'use strict';
// SCROLLSPY CLASS DEFINITION
==========================
.process()
}
ScrollSpy.VERSION = '3.3.7'
ScrollSpy.DEFAULTS = {
offset: 10
}
ScrollSpy.prototype.getScrollHeight = this.$body[0].scrollHeight,document.documentElement.scrollHeight)
}
ScrollSpy.prototype.refresh = ])
})
}
ScrollSpy.prototype.process = .activate(targets[i])
}
}
ScrollSpy.prototype.activate = )
}
ScrollSpy.prototype.clear = )
}
SCROLLSPY PLUGIN DEFINITION
===========================
Plugin(option) {
this.each( () {
var $this = $()
var data = $this.data('bs.scrollspy'var options = typeof option == 'object' && option
if (!data) $this.data('bs.scrollspy',(data = new ScrollSpy(,options)))
typeof option == 'string') data[option]()
})
}
var old = $.fn.scrollspy
$.fn.scrollspy = Plugin
$.fn.scrollspy.Constructor = ScrollSpy
SCROLLSPY NO CONFLICT
=====================
$.fn.scrollspy.noConflict = () {
$.fn.scrollspy = old
}
SCROLLSPY DATA-API
==================
$(window).on('load.bs.scrollspy.data-api',1)"> () {
$('[data-spy="scroll"]').each(var $spy = $()
Plugin.call($spy,$spy.data())
})
})
}(jQuery);