Super Cool jQuery Rocket-to-the-Top Effect

Add-ons
2026-07-21 12:57 5 次浏览 • 0 次下载 34.2KB
Super Cool jQuery Rocket-to-the-Top Effect

Usage

Include jquery, TweenMax.min.js, and ScrollToPlugin.min.js in your page.

1
2
3
<script src="js/jquery.min.js"></script>

HTML Structure

The HTML structure for the back-to-top rocket is as follows:

1
2
3
4
5
<div id="shangxia2">
<span id="gotop">
<img src="img/huojian.svg" alt="Back-to-Top Rocket">
</span>
</div>

CSS Styles

Add the necessary CSS styles for the rocket: use fixed positioning to keep it in the bottom-right corner of the page. Then, add a rubberBand animation when the mouse hovers over the rocket. This animation uses the transform function to apply a 3D scaling effect to the rocket.

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
/* Rocket CSS */
#gotop1 {
width: 80px;
position: fixed;
bottom: 90px;
cursor: pointer;
z-index: 99998;
right: 50%;
margin-right: -620px;
}
/* Rocket Hover Effect */
#gotop1:hover {
animation: rubberBand 1s;
}
@keyframes rubberBand {
from {
transform: scale3d(1, 1, 1);
}
30% {
transform: scale3d(1.25, 0.75, 1);
}
40% {
transform: scale3d(0.75, 1.25, 1);
}
50% {
transform: scale3d(1.15, 0.85, 1);
}
65% {
transform: scale3d(.95, 1.05, 1);
}
75% {
transform: scale3d(1.05, .95, 1);
}
to {
transform: scale3d(1, 1, 1);
}
}

Initialize the Plugin

After the page DOM elements have finished loading, initialize the back-to-top effect using the following method.

1
2
3
4
5
6
7
$("#gotop").click(function(e) {
TweenMax.to(window, 1.5, {scrollTo:0, ease: Expo.easeInOut});
var huojian = new TimelineLite();
huojian.to("#gotop1", 1, {rotationY:720, scale:0.6, y:"+=40", ease: Power4.easeOut})
.to("#gotop1", 1, {y:-1000, opacity:0, ease: Power4.easeOut}, 0.6)
.to("#gotop1", 1, {y:0, rotationY:0, opacity:1, scale:1, ease: Expo.easeOut, clearProps: "all"}, "1.4");
});


星河码客

发现和分享优质开源项目,传承互联网精神,为开发者服务。

关于本站

联系我们

微信/广告合作:ITcloub (备注星河码客)

免责声明:本站资源版权归原作者所有,仅供学习与交流。如有侵权,请通过「关于我们 - 侵权投诉」联系删除。

Powered by Nuxt · Deployed on Cloudflare