Contents

點超連結頁面動畫特效

Contents

最近還有個東西沒記錄
點連結動畫特效
覺得還不錯,就小小研究
照下面網站參照做個小小範例
http://nora-anime.net/

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
<div class="header-menu">1</div>
<div class="header-menu">2</div>
<div class="header-menu">3</div>
<div class="header-menu">4</div>
<div class="header-menu">5</div>
<div class="header-menu">6</div>
<div class="header-menu">7</div>
<div class="header-menu">8</div>
<div class="header-menu">9</div>
<div class="header-menu">10</div>
<input type="button" id="btn" value="toggle" />
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
@keyframes menu-in-s {
    0% {
        opacity: 0;
        -webkit-transform: translateY(40px);
        transform: translateY(40px);
        -webkit-animation-timing-function: ease-out;
        animation-timing-function: ease-out
    }
    80% {
        opacity: 1;
        -webkit-transform: translateY(-4px);
        transform: translateY(-4px)
    }
    100% {
        -webkit-transform: translateY(0);
        transform: translateY(0)
    }
}

@keyframes menu-out-s {
    0% {
        opacity: 1;
        -webkit-transform: translateY(0);
        transform: translateY(0);
        -webkit-animation-timing-function: cubic-bezier(.23, 1, .32, 1);
        animation-timing-function: cubic-bezier(.23, 1, .32, 1)
    }
    100% {
        opacity: 0;
        -webkit-transform: translateY(40px);
        transform: translateY(40px);
    }
}
.header-menu:nth-of-type(1) {
    -webkit-animation: menu-in-s .4s linear 0s 1 normal both;
    animation: menu-in-s .4s linear 0s 1 normal both
}
.header-menu:nth-of-type(2) {
    -webkit-animation: menu-in-s .4s linear .05s 1 normal both;
    animation: menu-in-s .4s linear .05s 1 normal both
}
.header-menu:nth-of-type(3) {
    -webkit-animation: menu-in-s .4s linear .1s 1 normal both;
    animation: menu-in-s .4s linear .1s 1 normal both
}
.header-menu:nth-of-type(4) {
    -webkit-animation: menu-in-s .4s linear .15s 1 normal both;
    animation: menu-in-s .4s linear .15s 1 normal both
}
.header-menu:nth-of-type(5) {
    -webkit-animation: menu-in-s .4s linear .2s 1 normal both;
    animation: menu-in-s .4s linear .2s 1 normal both
}
.header-menu:nth-of-type(6) {
    -webkit-animation: menu-in-s .4s linear .25s 1 normal both;
    animation: menu-in-s .4s linear .25s 1 normal both
}
.header-menu:nth-of-type(7) {
    -webkit-animation: menu-in-s .4s linear .3s 1 normal both;
    animation: menu-in-s .4s linear .3s 1 normal both
}
.header-menu:nth-of-type(8) {
    -webkit-animation: menu-in-s .4s linear .35s 1 normal both;
    animation: menu-in-s .4s linear .35s 1 normal both
}
.header-menu:nth-of-type(9) {
    -webkit-animation: menu-in-s .4s linear .4s 1 normal both;
    animation: menu-in-s .4s linear .4s 1 normal both
}
.header-menu:nth-of-type(10) {
    -webkit-animation: menu-in-s .4s linear .45s 1 normal both;
    animation: menu-in-s .4s linear .45s 1 normal both
}



.header-menu-fadeout:nth-of-type(1) {
    -webkit-animation: menu-out-s .4s linear .36s 1 normal both;
    animation: menu-out-s .4s linear .36s 1 normal both
}
.header-menu-fadeout:nth-of-type(2) {
    -webkit-animation: menu-out-s .4s linear .32s 1 normal both;
    animation: menu-out-s .4s linear .32s 1 normal both
}
.header-menu-fadeout:nth-of-type(3) {
    -webkit-animation: menu-out-s .4s linear .28s 1 normal both;
    animation: menu-out-s .4s linear .28s 1 normal both
}
.header-menu-fadeout:nth-of-type(4) {
    -webkit-animation: menu-out-s .4s linear .24s 1 normal both;
    animation: menu-out-s .4s linear .24s 1 normal both
}
.header-menu-fadeout:nth-of-type(5) {
    -webkit-animation: menu-out-s .4s linear .2s 1 normal both;
    animation: menu-out-s .4s linear .2s 1 normal both
}
.header-menu-fadeout:nth-of-type(6) {
    -webkit-animation: menu-out-s .4s linear .16s 1 normal both;
    animation: menu-out-s .4s linear .16s 1 normal both
}
.header-menu-fadeout:nth-of-type(7) {
    -webkit-animation: menu-out-s .4s linear .12s 1 normal both;
    animation: menu-out-s .4s linear .12s 1 normal both
}
.header-menu-fadeout:nth-of-type(8) {
    -webkit-animation: menu-out-s .4s linear .08s 1 normal both;
    animation: menu-out-s .4s linear .08s 1 normal both
}
.header-menu-fadeout:nth-of-type(9) {
    -webkit-animation: menu-out-s .4s linear .04s 1 normal both;
    animation: menu-out-s .4s linear .04s 1 normal both
}
.header-menu-fadeout:nth-of-type(10) {
    -webkit-animation: menu-out-s .4s linear 0s 1 normal both;
    animation: menu-out-s .4s linear 0s 1 normal both
}


.header-menu-fadeout{
  pointer-events: none;
}
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
document.getElementById('btn').addEventListener("click",function(){
 document.querySelectorAll('.header-menu').forEach((el)=>{
   var className = "header-menu-fadeout";
  if (el.classList) {
  el.classList.toggle(className);
} else {
  var classes = el.className.split(' ');
  var existingIndex = classes.indexOf(className);

  if (existingIndex >= 0)
    classes.splice(existingIndex, 1);
  else
    classes.push(className);

  el.className = classes.join(' ');
}
 });
});

可用event.preventDefault();來解決a連結事件動作
css可用SASS用回圈寫
JS Bin on jsbin.com