-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathanimate.easing.html
153 lines (147 loc) · 4.42 KB
/
animate.easing.html
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<!DOCTYPE html>
<html dir="ltr" lang="en-US">
<head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Пример расширения объекта easing</title>
<link rel="profile" href="https://gmpg.org/xfn/11"/>
<link rel="shortcut icon" href="https://anton.shevchuk.name/favicon.ico"/>
<link rel="stylesheet" href="css/styles.css"/>
<style>
.heart {
width: 200px;
height: 200px;
overflow: hidden;
position: relative;
border-radius: 4px;
margin: 0 auto 4px;
}
.heart img {
position: absolute;
margin: 50px;
width: 100px;
height: 100px;
border: 0
}
.heart p {
position: absolute;
width: 200px;
padding: 0;
text-align: center;
margin-top: 8px;
font-weight: 700;
}
.block {
height: 100px;
}
.target {
height: 10px;
border-bottom: 2px #fe3456 dotted;
}
</style>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/code.js"></script>
<script type="text/javascript">
$.extend($.easing, {
/**
* Heart Beat
*
* @param x
* @param t current time
* @param b begining
* @param c change in value
* @param d duration
*
* @link https://habrahabr.ru/blogs/mootools/43379/
*/
heart: function (x) {
if (x < 0.3) return Math.pow(x, 4) * 49.4
if (x < 0.4) return 9 * x - 2.3
if (x < 0.5) return -13 * x + 6.5
if (x < 0.6) return 4 * x - 2
if (x < 0.7) return 0.4
if (x < 0.75) return 4 * x - 2.4
if (x < 0.8) return -4 * x + 3.6
if (x >= 0.8) return 1 - Math.sin(Math.acos(x))
},
heartIn: function (x) {
return x === 0 ? 0 : $.easing.heart(x)
},
heartOut: function (x) {
if (x < 0.3) return $.easing.heartIn(x)
return x === 1 ? 1 : 1 - $.easing.heart(x)
},
heartInOut: function (x) {
if (x < 0.5) return $.easing.heartIn(x)
return $.easing.heartOut(x)
}
})
$(function () {
$('.heart').click(function () {
let easing = $(this).data('easing')
$(this).find('img')
.animate({ width: '-=50px', height: '-=50px', left: '+=25px', top: '+=50px' }, 3000, easing)
.animate({ width: '+=50px', height: '+=50px', left: '-=25px', top: '-=50px' }, 200)
})
})
</script>
</head>
<body>
<header>
<h1>Пример расширять объект easing</h1>
<h2>Пробуем, играемся, и мотаем на ус (покликайте по сердцам)</h2>
</header>
<main>
<article>
<div class="block">
<div class="target"></div>
</div>
<div class="heart" data-easing="heartIn">
<p>heartIn</p>
<img src="images/heart.png" alt="Heart"/>
</div>
<div class="heart" data-easing="heartOut">
<p>heartOut</p>
<img src="images/heart.png" alt="Heart"/>
</div>
<div class="heart" data-easing="heartInOut">
<p>heartInOut</p>
<img src="images/heart.png" alt="Heart"/>
</div>
</article>
</main>
<footer>
© <a href="https://anton.shevchuk.name/jquery-book/">jQuery for beginners</a>
</footer>
<aside>
<nav>
<a href="animate.step.html" title="go prev" rel="prev">Prev</a>
<a href="index.html#90" title="back to Index" rel="index">Index</a>
<a href="#" title="reload" onclick="window.location.reload();return false">Reload</a>
<a href="sizzle.filter.html" title="go next" rel="next">Next</a>
</nav>
<hr/>
<code>$(<span>".target"</span>)
.animate(
{height:<span>"+=200px"</span>},
3000,
<span>"heartIn"</span>
)</code>
<button type="button">Run Code</button>
<code>$(<span>".target"</span>)
.animate(
{height:<span>"+=200px"</span>},
3000,
<span>"heartOut"</span>
)</code>
<button type="button">Run Code</button>
<code>$(<span>".target"</span>)
.animate(
{height:<span>"+=200px"</span>},
3000,
<span>"heartInOut"</span>
)</code>
<button type="button">Run Code</button>
</aside>
</body>
</html>