Skip to content

Commit 7611ff0

Browse files
committed
[v1.6 alpha] enhance navbar a lot, both function and animation
1 parent 9249f34 commit 7611ff0

File tree

4 files changed

+86
-33
lines changed

4 files changed

+86
-33
lines changed

_includes/nav.html

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@
1313
</div>
1414

1515
<!-- Collect the nav links, forms, and other content for toggling -->
16-
<!-- Known Issue, found by Hux:
17-
<nav>'s height woule be hold on by its content.
18-
so, when navbar scale out, the <nav> will cover tags.
19-
also mask any touch event of tags, unfortunately.
20-
-->
2116
<div id="huxblog_navbar">
2217
<div class="navbar-collapse">
2318
<ul class="nav navbar-nav navbar-right">
@@ -45,22 +40,38 @@
4540
var $navbar = document.querySelector('#huxblog_navbar');
4641
var $collapse = document.querySelector('.navbar-collapse');
4742

48-
$toggle.addEventListener('click', handleMagic)
49-
function handleMagic(e){
50-
if ($navbar.className.indexOf('in') > 0) {
51-
// CLOSE
52-
$navbar.className = " ";
43+
var __HuxNav__ = {
44+
close: function(){
45+
$navbar.className = " ";
5346
// wait until animation end.
5447
setTimeout(function(){
5548
// prevent frequently toggle
5649
if($navbar.className.indexOf('in') < 0) {
5750
$collapse.style.height = "0px"
5851
}
5952
},400)
60-
}else{
61-
// OPEN
53+
},
54+
open: function(){
6255
$collapse.style.height = "auto"
6356
$navbar.className += " in";
6457
}
6558
}
59+
60+
// Bind Event
61+
$toggle.addEventListener('click', function(e){
62+
if ($navbar.className.indexOf('in') > 0) {
63+
__HuxNav__.close()
64+
}else{
65+
__HuxNav__.open()
66+
}
67+
})
68+
69+
$toggle.addEventListener('touchstart', function(e){
70+
// stop propagating event to document.
71+
e.stopPropagation();
72+
})
73+
74+
document.addEventListener('touchstart', function(e){
75+
__HuxNav__.close();
76+
})
6677
</script>

css/hux-blog.css

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -211,24 +211,39 @@ pre code {
211211
margin-top: 20px;
212212
}
213213
@media only screen and (max-width: 767px) {
214+
/**
215+
* Layout
216+
* Since V1.6 we use absolute positioning to prevent to expand container-fluid
217+
* which would cover tags. A absolute positioning make a new layer.
218+
*/
214219
.navbar-default .navbar-collapse {
220+
position: absolute;
221+
right: 0;
215222
border: none;
216223
background: white;
217224
box-shadow: 0px 5px 10px 2px rgba(0, 0, 0, 0.2);
218225
box-shadow: rgba(0, 0, 0, 0.117647) 0px 1px 6px, rgba(0, 0, 0, 0.239216) 0px 1px 4px;
219226
border-radius: 2px;
220227
width: 170px;
221-
float: right;
222-
margin: 0px;
223228
}
229+
/**
230+
* Animation
231+
* HuxBlog-Navbar using genuine Material Design Animation
232+
*/
224233
#huxblog_navbar {
234+
/**
235+
* Sharable code and 'out' function
236+
*/
225237
opacity: 0;
226238
transform: scaleX(0);
227239
transform-origin: top right;
228-
transition: all 0.25s cubic-bezier(0.23, 1, 0.32, 1);
240+
transition: all 200ms cubic-bezier(0.47, 0, 0.4, 0.99) 0ms;
229241
-webkit-transform: scaleX(0);
230242
-webkit-transform-origin: top right;
231-
-webkit-transition: all 0.25s cubic-bezier(0.23, 1, 0.32, 1);
243+
-webkit-transition: all 200ms cubic-bezier(0.47, 0, 0.4, 0.99) 0ms;
244+
/**
245+
*'In' Animation
246+
*/
232247
}
233248
#huxblog_navbar a {
234249
font-size: 13px;
@@ -238,27 +253,33 @@ pre code {
238253
height: 0px;
239254
transform: scaleY(0);
240255
transform-origin: top right;
241-
transition: transform 500ms cubic-bezier(0.23, 1, 0.32, 1);
256+
transition: transform 400ms cubic-bezier(0.32, 1, 0.23, 1) 0ms;
242257
-webkit-transform: scaleY(0);
243258
-webkit-transform-origin: top right;
244-
-webkit-transition: -webkit-transform 500ms cubic-bezier(0.23, 1, 0.32, 1);
259+
-webkit-transition: -webkit-transform 400ms cubic-bezier(0.32, 1, 0.23, 1) 0ms;
245260
}
246261
#huxblog_navbar li {
247262
opacity: 0;
248-
transition: opacity 450ms cubic-bezier(0.23, 1, 0.32, 1) 205ms;
249-
-webkit-transition: opacity 450ms cubic-bezier(0.23, 1, 0.32, 1) 205ms;
263+
transition: opacity 100ms cubic-bezier(0.23, 1, 0.32, 1) 0ms;
264+
-webkit-transition: opacity 100ms cubic-bezier(0.23, 1, 0.32, 1) 0ms;
250265
}
251266
#huxblog_navbar.in {
252267
transform: scaleX(1);
253268
-webkit-transform: scaleX(1);
254269
opacity: 1;
270+
transition: all 250ms cubic-bezier(0.23, 1, 0.32, 1) 0ms;
271+
-webkit-transition: all 250ms cubic-bezier(0.23, 1, 0.32, 1) 0ms;
255272
}
256273
#huxblog_navbar.in .navbar-collapse {
257274
transform: scaleY(1);
258275
-webkit-transform: scaleY(1);
276+
transition: transform 500ms cubic-bezier(0.23, 1, 0.32, 1);
277+
-webkit-transition: -webkit-transform 500ms cubic-bezier(0.23, 1, 0.32, 1);
259278
}
260279
#huxblog_navbar.in li {
261280
opacity: 1;
281+
transition: opacity 450ms cubic-bezier(0.23, 1, 0.32, 1) 205ms;
282+
-webkit-transition: opacity 450ms cubic-bezier(0.23, 1, 0.32, 1) 205ms;
262283
}
263284
}
264285
.navbar-custom {

0 commit comments

Comments
 (0)