Skip to content

Commit 5ee0e61

Browse files
committed
directive modifiers
1 parent c0fcce8 commit 5ee0e61

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

index.html

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,36 @@
66
</head>
77
<body>
88
<div id="app">
9-
<h1 v-switching-color="colors">Vue School</h1>
9+
<h1 v-switching-color:fast.underline.textcenter="colors">Vue School</h1>
1010
</div>
1111

1212
<script type="text/javascript">
1313
Vue.directive('switching-color', function (el, binding) {
14+
const modifiers = binding.modifiers
15+
if (modifiers.underline) {
16+
el.style.textDecoration = 'underline'
17+
}
18+
if (modifiers.textcenter) {
19+
el.style.textAlign = 'center'
20+
}
21+
22+
const speeds = {
23+
slow: 2000,
24+
normal: 1000,
25+
fast: 500,
26+
crazy: 100
27+
}
28+
const speedName = binding.arg || 'normal'
29+
const speed = speeds[speedName]
30+
1431
const colors = binding.value
1532
let i = 0
1633
setInterval(() => {
1734
el.style.color = colors[i++]
1835
if (i > colors.length - 1) {
1936
i = 0
2037
}
21-
}, 500)
38+
}, speed)
2239
})
2340

2441
new Vue({

0 commit comments

Comments
 (0)