Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
bootstrap
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
bootstrap
Commits
475dbe58
Commit
475dbe58
authored
May 23, 2014
by
Chris Rebert
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #13589 from mrobinet/scrollspy-maxScroll-with-offset
Adjust for Scrollspy offset when calculating maxScroll.
parents
bc1ce426
c2e94eba
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
3 deletions
+37
-3
js/scrollspy.js
js/scrollspy.js
+1
-1
js/tests/unit/scrollspy.js
js/tests/unit/scrollspy.js
+36
-2
No files found.
js/scrollspy.js
View file @
475dbe58
...
...
@@ -69,7 +69,7 @@
ScrollSpy
.
prototype
.
process
=
function
()
{
var
scrollTop
=
this
.
$scrollElement
.
scrollTop
()
+
this
.
options
.
offset
var
scrollHeight
=
this
.
$scrollElement
[
0
].
scrollHeight
||
Math
.
max
(
this
.
$body
[
0
].
scrollHeight
,
document
.
documentElement
.
scrollHeight
)
var
maxScroll
=
scrollHeight
-
this
.
$scrollElement
.
height
()
var
maxScroll
=
this
.
options
.
offset
+
scrollHeight
-
this
.
$scrollElement
.
height
()
var
offsets
=
this
.
offsets
var
targets
=
this
.
targets
var
activeTarget
=
this
.
activeTarget
...
...
js/tests/unit/scrollspy.js
View file @
475dbe58
...
...
@@ -42,7 +42,8 @@ $(function () {
ok
(
$topbar
.
find
(
'
.active
'
,
true
))
})
test
(
'
should only switch active class on current target
'
,
function
()
{
asyncTest
(
'
should only switch active class on current target
'
,
function
()
{
expect
(
1
);
var
sectionHTML
=
'
<div id="root" class="active">
'
+
'
<div class="topbar">
'
+
'
<div class="topbar-inner">
'
+
...
...
@@ -75,7 +76,40 @@ $(function () {
.
find
(
'
#scrollspy-example
'
)
.
bootstrapScrollspy
({
target
:
'
#ss-target
'
})
$scrollSpy
.
on
(
'
scroll.bs.scrollspy
'
,
function
()
{
ok
(
$section
.
hasClass
(
'
active
'
),
'
Active class still on root node
'
)
start
()
})
$scrollSpy
.
scrollTop
(
350
);
ok
(
$section
.
hasClass
(
'
active
'
),
'
Active class still on root node
'
)
})
asyncTest
(
'
middle navigation option correctly selected when large offset is used
'
,
function
()
{
expect
(
3
);
var
sectionHTML
=
'
<div id="header" style="height: 500px;"></div>
'
+
'
<nav id="navigation" class="navbar">
'
+
'
<ul class="nav navbar-nav">
'
+
'
<li class="active"><a id="one-link" href="#one">One</a></li>
'
+
'
<li><a id="two-link" href="#two">Two</a></li>
'
+
'
<li><a id="three-link" href="#three">Three</a></li>
'
+
'
</ul>
'
+
'
</nav>
'
+
'
<div id="content" style="height: 200px; overflow-y: auto;">
'
+
'
<div id="one" style="height: 500px;"></div>
'
+
'
<div id="two" style="height: 300px;"></div>
'
+
'
<div id="three" style="height: 10px;"></div>
'
+
'
</div>
'
,
$section
=
$
(
sectionHTML
).
appendTo
(
'
#qunit-fixture
'
),
$scrollSpy
=
$section
.
show
()
.
filter
(
'
#content
'
)
$scrollSpy
.
bootstrapScrollspy
({
target
:
'
#navigation
'
,
offset
:
$scrollSpy
.
position
().
top
})
$scrollSpy
.
on
(
'
scroll.bs.scrollspy
'
,
function
()
{
ok
(
!
$section
.
find
(
'
#one-link
'
).
parent
().
hasClass
(
'
active
'
),
'
Active class removed from first section
'
)
ok
(
$section
.
find
(
'
#two-link
'
).
parent
().
hasClass
(
'
active
'
),
'
Active class on middle section
'
)
ok
(
!
$section
.
find
(
'
#three-link
'
).
parent
().
hasClass
(
'
active
'
),
'
Active class not on last section
'
)
start
()
})
$scrollSpy
.
scrollTop
(
550
);
})
})
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment