Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Commit 0cb1d46

Browse files
author
Victor George
committed
sticky fixed thanks to @Vikas!
1 parent 1fddd50 commit 0cb1d46

File tree

7 files changed

+87
-13
lines changed

7 files changed

+87
-13
lines changed

app/directives/tc-sticky/tc-sticky.directive.jade

Whitespace-only changes.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
2+
(function() {
3+
'use strict';
4+
5+
angular.module('tcUIComponents').directive('tcSticky', ['CONSTANTS', '$window', tcSticky]);
6+
7+
function tcSticky(CONSTANTS, $window) {
8+
return {
9+
restrict: 'A',
10+
link: function(scope, element) {
11+
scope.width = element.prop('offsetWidth');
12+
var elWidth = scope.width + 'px',
13+
elChild = angular.element(element[0].querySelector(':first-child'));
14+
elChild.css('width', elWidth);
15+
angular.element($window).bind("scroll", function() {
16+
var affixElement = document.getElementById('affix'),
17+
xPosition = 0,
18+
yPosition = 0;
19+
function getPosition(element) {
20+
while(element) {
21+
yPosition += (element.offsetTop - element.scrollTop + element.clientTop);
22+
element = element.offsetParent;
23+
}
24+
}
25+
getPosition(affixElement);
26+
var height = angular.element(affixElement).prop('offsetHeight');
27+
var top = angular.element(affixElement).prop('offsetTop');
28+
// console.log(yPosition);
29+
// console.log(angular.element(document).scrollTop);
30+
// console.log(elChild[0].clientTop);
31+
if (yPosition >= 0 || $window.innerHeight <= elChild[0].offsetHeight || $window.innerWidth < 768) {
32+
elChild.removeClass('affix affix-bottom');
33+
} else if ( yPosition < 0) {
34+
console.log(top + height);
35+
console.log(yPosition);
36+
console.log(top + height + yPosition);
37+
if (top + height + yPosition < 800) {
38+
elChild.addClass('affix-bottom');
39+
elChild.removeClass('affix');
40+
} else {
41+
elChild.removeClass('affix-bottom');
42+
elChild.addClass('affix');
43+
}
44+
45+
};
46+
});
47+
}
48+
};
49+
}
50+
})();

app/index.jade

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ html
6060
link(rel="stylesheet", href="assets/css/directives/toggle-password-with-tips.css")
6161
link(rel="stylesheet", href="assets/css/directives/toggle-password.css")
6262
link(rel="stylesheet", href="assets/css/directives/tc-tabs.css")
63+
link(rel="stylesheet", href="assets/css/directives/tc-sticky.css")
6364
link(rel="stylesheet", href="assets/css/directives/tc-section.css")
6465
link(rel="stylesheet", href="assets/css/directives/tc-paginator.css")
6566
link(rel="stylesheet", href="assets/css/directives/tc-endless-paginator.css")
@@ -195,6 +196,7 @@ html
195196
script(src="directives/tc-endless-paginator/tc-endless-paginator.directive.js")
196197
script(src="directives/tc-paginator/tc-paginator.directive.js")
197198
script(src="directives/tc-section/tc-section.directive.js")
199+
script(src="directives/tc-sticky/tc-sticky.directive.js")
198200
script(src="directives/tc-tabs/tc-tabs.directive.js")
199201
script(src="directives/tc-transclude.directive.js")
200202
script(src="directives/track-toggle/track-toggle.directive.js")

app/profile/about/about.jade

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
.about-container
22

3-
.profile-header-container(ng-cloak)
3+
.profile-header-container(ng-cloak,id="affix", tc-sticky)
44
//- .sticky-container(sticky media-query="min-width: 780px" use-placeholder="true" offset="10" confine="true" sticky-class="sticked")
55
profile-widget(profile="profileVm.profile", edit-profile-link="profileVm.showEditProfileLink", num-wins="profileVm.numWins", profile-vm="profileVm")
66
77
//- .sticky-container(bs-affix data-offset-top="10" data-offset-bottom="400")
8-
.sticky-container
8+
.sticky-container()
99
profile-widget(profile="profileVm.profile", edit-profile-link="profileVm.showEditProfileLink", num-wins="profileVm.numWins", profile-vm="profileVm")
1010

1111

assets/css/directives/profile-widget.scss

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,17 +86,19 @@
8686
flex-direction: column;
8787
align-items: center;
8888
margin-top: 40px;
89+
width: 100%;
90+
8991

9092
.tracks {
9193
display: flex;
9294
flex-direction: row;
9395
justify-content: center;
94-
overflow-x: auto;
95-
overflow-y: hidden;
96+
9697
.track {
9798
cursor: pointer;
9899
display: flex;
99100
width: 100%;
101+
flex-wrap: wrap;
100102
flex-direction: column;
101103
align-items: center;
102104
+ .track {
@@ -114,8 +116,8 @@
114116
margin-top: 11px;
115117
text-transform: uppercase;
116118
text-align: center;
117-
white-space: nowrap;
118-
// word-wrap: break-word;
119+
// white-space: nowrap;
120+
word-wrap: break-word;
119121
}
120122
}
121123
}

assets/css/directives/tc-sticky.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// .affix {
2+
// position:fixed !important;
3+
// top: 0; //Change this value to match your needs;
4+
// z-index: 10;
5+
// }

assets/css/profile/about.scss

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,14 @@
2626
width: 100%;
2727
margin-bottom: 5px;
2828
display: flex;
29-
3029
position: relative;
3130
margin-left: 10px;
3231

3332

3433
@media (min-width: 768px) {
35-
max-width: 348px;
34+
max-width: 368px;
3635
margin: 0 auto;
37-
padding-left: 10px;
36+
padding-right: 10px;
3837
display: block;
3938
position: relative;
4039

@@ -46,13 +45,29 @@
4645
margin: 0 auto;
4746
display: block;
4847
width: 100%;
48+
@media (min-width: 768px){
49+
box-sizing: border-box;
50+
width: 338px;
51+
margin: 0;
52+
}
4953
padding: 30px 34px;
50-
top: 0;
51-
margin: 0 auto;
54+
margin: 0 10px;
55+
transition: .2s all;
5256
}
5357

54-
.sticky.sticked {
55-
58+
.sticky-container.affix {
59+
position:fixed;
60+
top: 10px;
61+
bottom: auto;
62+
z-index: 10;
63+
}
64+
65+
.sticky-container.affix-bottom {
66+
position: absolute;
67+
bottom: 0;
68+
z-index: 10;
69+
top: auto;
70+
5671
}
5772
}
5873

0 commit comments

Comments
 (0)