Skip to content

Commit c7256e0

Browse files
committed
Theming: handle panning/swiping in offcanvas properly
1 parent 04db853 commit c7256e0

File tree

3 files changed

+41
-58
lines changed

3 files changed

+41
-58
lines changed

src/Presentation/SmartStore.Web/Themes/Alpha/Content/_shopbar.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
font-size: 10px;
9292
line-height: 1.3;
9393
vertical-align: middle;
94-
white-space: normal;
94+
white-space: nowrap;
9595
overflow: hidden;
9696
text-overflow: ellipsis;
9797
}

src/Presentation/SmartStore.Web/Themes/Alpha/Content/shared/_offcanvas.scss

Lines changed: 16 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -48,62 +48,16 @@ body.canvas-noscroll {
4848
}
4949

5050

51-
/* HAMBURGER
51+
/* TOGGLER
5252
--------------------------------------------*/
5353

5454
.navbar-toggler {
5555
position: relative;
5656
background-color: transparent;
57-
/*
58-
width: 3.2rem;
59-
height: 3.2rem;
60-
*/
6157
outline: none;
6258
&:focus { outline: none }
6359
}
6460

65-
.navbar-toggler .hamburger {
66-
display: block;
67-
position: relative;
68-
margin: 0 auto;
69-
70-
&, &:before, &:after {
71-
background-color: #fff;
72-
width: 1.6rem;
73-
height: 3px;
74-
border-radius: 1px;
75-
transition: background-color $offcanvas-duration $offcanvas-easing,
76-
transform $offcanvas-duration $offcanvas-easing;
77-
}
78-
79-
&:before, &:after {
80-
display: block;
81-
content: '';
82-
position: absolute;
83-
opacity: 1 !important;
84-
}
85-
&:before {
86-
top: 8px;
87-
}
88-
&:after {
89-
top: -8px;
90-
}
91-
92-
.navbar-light &, .navbar-light &:before, .navbar-light &:after {
93-
background-color: $body-color;
94-
}
95-
96-
.canvas-sliding & {
97-
background-color: transparent !important;
98-
&:before {
99-
transform: translate3d(0, -8px, 0) rotate(45deg);
100-
}
101-
&:after {
102-
transform: translate3d(0, 8px, 0) rotate(-45deg);
103-
}
104-
}
105-
}
106-
10761

10862
/* PARENT CANVAS BLOCKER
10963
--------------------------------------------*/
@@ -165,12 +119,6 @@ body.canvas-blocking .canvas-blocker {
165119
width: 100%;
166120
}
167121

168-
&.on {
169-
visibility: visible;
170-
transition: transform $offcanvas-duration $offcanvas-easing;
171-
transform: translate3d(0, 0, 0) !important;
172-
}
173-
174122
&.offcanvas-push,
175123
&.offcanvas-overlay {
176124
transform: translate3d(-100%, 0, 0);
@@ -195,6 +143,16 @@ body.canvas-blocking .canvas-blocker {
195143
@media (max-width: $offcanvas-width-lg) {
196144
&.offcanvas-lg { width: 100%; }
197145
}
146+
147+
&.offcanvas-push.on,
148+
&.offcanvas-overlay.on,
149+
&.offcanvas-right.on,
150+
&.on {
151+
// specificity: we want to prevent "!important" here
152+
visibility: visible;
153+
transition: transform $offcanvas-duration $offcanvas-easing;
154+
transform: translate3d(0, 0, 0);
155+
}
198156
}
199157

200158
.offcanvas-content {
@@ -203,6 +161,11 @@ body.canvas-blocking .canvas-blocker {
203161
height: 100%;
204162
overflow-x: hidden;
205163
overflow-y: auto;
164+
165+
* {
166+
// Fixes Chrome 55+ pan/swipe bug
167+
touch-action: pan-y;
168+
}
206169
}
207170

208171

src/Presentation/SmartStore.Web/Themes/Alpha/Scripts/offcanvas.js

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,30 @@
4848
this.toggle();
4949
}
5050

51-
// Close on swipe
52-
var swipeEvent = el.hasClass('offcanvas-right') ? 'swiperight' : 'swipeleft';
53-
el.children().first().hammer({}).on(swipeEvent, function (e) {
54-
self.hide();
51+
// Close on pan[left|right]
52+
var onRight = el.hasClass('offcanvas-right'),
53+
canPan = el.hasClass('offcanvas-overlay');
54+
55+
el.children().first().hammer({}).on('panstart panend panleft panright', function (e) {
56+
var delta = onRight
57+
? Math.max(0, e.gesture.deltaX)
58+
: Math.min(0, e.gesture.deltaX);
59+
60+
if (e.type.toLowerCase() === 'panstart') {
61+
el.css('transition', 'none');
62+
}
63+
else if (e.type.toLowerCase() === 'panend') {
64+
el.css('transform', '').css('transition', '');
65+
if (Math.abs(delta) >= 100) {
66+
self.hide();
67+
}
68+
}
69+
else {
70+
// panleft or panright
71+
if (canPan) {
72+
el.css('transform', 'translate3d(' + delta + 'px, 0, 0)');
73+
}
74+
}
5575
});
5676
}
5777

0 commit comments

Comments
 (0)