svg+jquery实现一个差异滚动海上小岛效果代码
代码语言:html
所属分类:视觉差异
代码描述:svg+jquery实现一个差异滚动海上小岛效果代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<link type="text/css" rel="stylesheet" href="//repo.bfw.wiki/bfwrepo/css/reset.min.css">
<style>
/* END COLOURS */
/*
===========================
General styling
===========================
*/
body {
background-color: #17517b; }
#parallax {
height: 150vh;
width: 100%;
overflow: hidden;
position: relative;
display: none; }
#parallax .layer {
position: fixed;
z-index: -1;
height: 100vh;
width: 100%;
background-position: bottom center;
background-size: cover;
background-repeat: no-repeat;
background-attachment: fixed; }
#parallax .layer svg {
position: absolute;
bottom: 0; }
section#topper {
position: relative; }
section#topper .background {
background: #75c9f0;
/* Old browsers */
background: -moz-linear-gradient(top, #75c9f0 1%, #75c9f0 1%, #d8e9eb 51%, #bfbada 100%);
/* FF3.6-15 */
background: -webkit-linear-gradient(top, #75c9f0 1%, #75c9f0 1%, #d8e9eb 51%, #bfbada 100%);
/* Chrome10-25,Safari5.1-6 */
background: linear-gradient(to bottom, #75c9f0 1%, #75c9f0 1%, #d8e9eb 51%, #bfbada 100%);
/* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#75c9f0', endColorstr='#bfbada',GradientType=0 );
/* IE6-9 */ }
section#topper .landscape-container {
width: 100%;
position: relative;
padding-top: 20px;
height: 100vh; }
section#topper .landscape-container .sky svg {
top: 0; }
section#topper .landscape-container .mountains-pink svg {
bottom: 3%; }
section#topper .landscape-container .mountains-purple svg {
bottom: 6%; }
section#topper .landscape-container .background-mountains svg {
bottom: 7%; }
section#topper .boat {
position: relative;
text-align: left; }
section#topper .boat svg {
height: 12%;
width: 12%;
position: relative;
left: 50px;
top: -300px; }
section#blue {
height: 800px;
width: 100%;
background-color: #17517b;
position: relative;
overflow: hidden; }
.svg-content {
display: inline-block;
overflow: hidden;
top: 0;
left: 0; }
svg {
padding: 0;
margin: 0;
display: block; }
.bubbles {
width: 10%;
height: 10%; }
/* ==========================================================================
Animations
========================================================================== */
@-webkit-keyframes swim {
0% {
margin-left: -35px; }
90% {
margin-left: 100%; }
100% {
margin-left: 100%; } }
@keyframes swim {
0% {
margin-left: -35px; }
100% {
margin-left: 100%; } }
svg.fish1 {
position: relative;
top: 50%;
right: 8%;
width: 10%;
height: 10%;
animation: swim 40s;
-webkit-animation: swim 40s;
animation-iteration-count: infinite;
-webkit-animation-iteration-count: infinite;
animation-timing-function: linear;
-webkit-animation-timing-function: linear;
animation-direction: reverse;
-webkit-animation-direction: reverse; }
svg.fish2 {
position: absolute;
bottom: 8%;
left: 8%;
width: 10%;
height: 10%;
animation: swim 40s;
-webkit-animation: swim 40s;
animation-iteration-count: infinite;
-webkit-animation-iteration-count: infinite;
animation-timing-function: linear;
-webkit-animation-timing-function: linear; }
svg .fish1,
svg .fish2 {
-moz-animation: fish-bounce 2s infinite;
-webkit-animation: fish-bounce 2s infinite;
animation: fish-bounce 2s infinite; }
@-moz-keyframes fish-bounce {
0%, 50%, 100% {
-moz-transform: translateY(0);
transform: translateY(0); }
25% {
-moz-transform: translateY(-2px);
transform: translateY(-2px); }
75% {
-moz-transform: translateY(-1px);
transform: translateY(-1px); } }
@-webkit-keyframes fish-bounce {
0%, 50%, 100% {
-webkit-transform: translateY(0);
transform: translateY(0); }
25% {
-webkit-transform: translateY(-2px);
transform: translateY(-2px); }
75% {
-webkit-transform: translateY(-1px);
transform: translateY(-1px); } }
@keyframes fish-bounce {
0%, 50%, 100% {
-moz-transform: translateY(0);
-ms-transform: translateY(0);
-webkit-transform: translateY(0);
transform: translateY(0); }
25% {
-moz-transform: translateY(-2px);
-ms-transform: translateY(-2px);
-webkit-transform: translateY(-2px);
transform: translateY(-2px); }
75% {
-moz-transform: translateY(-1px);
-ms-transform: translateY(-1px);
-webkit-transform: translateY(-1px);
transform: translateY(-1px); } }
.waves {
position: relative;
bottom: -200px;
height: 500px; }
.waves:after {
height: 50%;
background-color: #17517b;
content: '';
z-index: 2;
width: 100%;
display: block;
position: absolute;
bottom: -50%; }
.waves svg {
width: 108%; }
.waves svg > * {
position: relative; }
.waves svg > svg:nth-child(2) {
animation: move 5s infinite ease-in-out;
animation-delay: -2.5s;
right: 0; }
.waves svg > svg:nth-child(3) {
animation: move 5s infinite ease-in-out;
animation-delay: -3s;
right: 0; }
.waves svg > *:nth-child(4) {
animation: move 7s infinite ease-in-out;
animation-delay: -5s;
right: 0; }
.waves svg > *:nth-child(5) {
animation: move 9s infinite ease-in-out;
animation-delay: -2s; }
.waves svg > *:nth-child(6) {
animation: boat 11s infinite ease-in-out;
animation-delay: -9s; }
.waves svg > *:nth-child(7) {
animation: boat 7s infinite ease-in-out;
animation-delay: -5s; }
.waves svg > *:nth-child(8) {
animation: boat 5s infinite ease-in-out;
animation-delay: -3s; }
.waves svg > *:nth-child(9) {
animation: boat 11s infinite ease-in-out;
animation-delay: -9s; }
.floating {
z-index: auto;
-webkit-animation-name: floating;
animation-name: floating;
-webkit-animation-duration: 3s;
animation-duration: 3s;
-webkit-animation-iteration-count: infinite;
animation-iteration-count: infinite;
-webkit-animation-timing-function: ease-in-out;
animation-timing-function: ease-in-out; }
@-o-keyframes floating {
from {
transform: translate(0, 0); }
50% {
transform: translate(0, 10px); }
to {
transform: translate(0, 0); } }
@-ms-keyframes floating {
from {
transform: translate(0, 0); }
50% {
transform: translate(0, 10px); }
to {
transform: translate(0, 0); } }
@-webkit-keyframes floating {
from {
transform: translate(0, 0); }
50% {
transform: translate(0, 10px); }
to {
transform: translate(0, 0); } }
@-moz-keyframes floating {
from {
transform: translate(0, 0); }
50% {
transform: translate(0, 10px); }
to {
transform: translate(0, 0); } }
@keyframes floating {
from {
transform: translate(0, 0); }
50% {
transform: translate(0, 10px); }
to {
transform: translate(0, 0); } }
.boat {
z-index: auto;
-ms-animation-name: rocking;
-o-animation-name: rocking;
-moz-animation-name: rocking;
-webkit-animation-name: rocking;
animation-name: rocking;
-o-animation-duration: 3s;
-ms-animation-duration: 3s;
-moz-animation-duration: 3s;
-webkit-animation-duration: 3s;
animation-duration: 3s;
-o-animation-iteration-count: infinite;
-ms-animation-iteration-count: infinite;
-moz-animation-iteration-count: infinite;
-webkit-animation-iteration-count: infinite;
animation-iteration-count: infinite;
-o-animation-timing-function: ease-in-out;
-ms-animation-timing-function: ease-in-out;
-moz-animation-timing-function: ease-in-out;
-webkit-animation-timing-function: ease-in-out;
animation-timing-function: ease-in-out; }
@-o-keyframes rocking {
0% {
transform: rotate(-1deg); }
50% {
transform: rotate(1deg); }
100% {
transform: rotate(-1deg); } }
@-ms-keyframes rocking {
0% {
transform: rotate(-1deg); }
50% {
transform: rotate(1deg); }
100% {
transform: rotate(-1deg); } }
@-moz-keyframes rocking {
0% {
transform: rotate(-1deg); }
50% {
transform: rotate(1deg); }
100% {
transform: rotate(-1deg); } }
@-webkit-keyframes rocking {
0% {
transform: rotate(-1deg); }
50% {
transform: rotate(1deg); }
100% {
transform: rotate(-1deg); } }
@keyframes rocking {
0% {
transform: rotate(-1deg); }
50% {
transform: rotate(1deg); }
100% {
transform: rotate(-1deg); } }
.cloud.one {
opacity: 0.9;
-webkit-animation: drift 95s linear infinite;
-moz-animation: drift 95s linear infinite;
-o-animation: drift 95s linear infinite;
-ms-animation: drift 95s linear infinite;
animation: drift 95s linear infinite; }
.cloud.two {
-webkit-animation: drift 70s linear infinite;
-moz-animation: drift 70s linear infinite;
-o-animation: drift 70s linear infinite;
-ms-animation: drift 70s linear infinite;
animation: drift 70s linear infinite; }
/* Animation for the drifting clouds */
@-webkit-keyframes drift {
0% {
opacity: 1;
-webkit-transform: translateX(0px); }
50% {
opacity: 0.7;
-webkit-transform: translateX(200%); }
100% {
opacity: 1;
-webkit-transform: translateX(0px); } }
@-moz-keyframes drift {
0% {
opacity: 1;
-moz-transform: translateX(0px); }
50% {
opacity: 0.7;
-moz-transform: translateX(200%); }
100% {
opacity: 1;
-moz-transform: translateX(0px); } }
@-o-keyframes drift {
0% {
opacity: 1;
-o-transform: translateX(0px); }
50% {
opacity: 0.7;
-o-transform: translateX(200%); }
100% {
opacity: 1;
-o-transform: translateX(0px); } }
@-ms-keyframes drift {
0% {
opacity: 1;
-ms-transform: translateX(0px); }
50% {
opacity: 0.7;
-ms-transform: translateX(200%); }
100% {
opacity: 1;
-ms-transform: translateX(0px); } }
@keyframes drift {
0% {
opacity: 1;
transform: translateX(0px); }
50% {
opacity: 0.7;
transform: translateX(200%); }
100% {
opacity: 1;
-webkit-transform: translateX(0px); } }
@-o-keyframes move {
0% {
transform: translateX(0); }
50% {
transform: translateX(-50px); }
100% {
transform: translateX(0); } }
@-ms-keyframes move {
0% {
transform: translateX(0); }
50% {
transform: translateX(-50px); }
100% {
transform: translateX(0); } }
@-webkit-keyframes move {
0% {
transform: translateX(0); }
50% {
transform: translateX(-50px); }
100% {
transform: translateX(0); } }
@-moz-keyframes move {
0% {
transform: translateX(0); }
50% {
transform: translateX(-50px); }
100% {
transform: translateX(0); } }
@keyframes move {
0% {
transform: translateX(0); }
50% {
transform: translateX(-50px); }
100% {
transform: translateX(0); } }
@-o-keyframes boat {
0% {
transform: translateX(0); }
50% {
transform: translateX(-50px); }
100% {
transform: translateX(0); } }
@-ms-keyframes boat {
0% {
transform: translateX(0); }
50% {
transform: translateX(-50px); }
100% {
transform: translateX(0); } }
@-moz-keyframes boat {
0% {
transform: translateX(0); }
50% {
transform: translateX(-50px); }
100% {
transform: translateX(0); } }
@-webkit-keyframes boat {
0% {
transform: translateX(0); }
50% {
transform: translateX(-50px); }
100% {
transform: translateX(0); } }
@keyframes boat {
0% {
transform: translateX(0); }
50% {
transform: translateX(-50px); }
100% {
transform: translateX(0); } }
@keyframes bounce {
0%, 40%, 50%, 80%, 100% {
-moz-transform: translateY(0);
-ms-transform: translateY(0);
-o-transform: translateY(0);
-webkit-transform: translateY(0);
transform: translateY(0); }
10% {
-moz-transform: translateY(-6px);
-ms-transform: translateY(-6px);
-o-transform: translateY(-6px);
-webkit-transform: translateY(-6px);
transform: translateY(-6px); }
20% {
-moz-transform: translateY(0px);
-ms-transform: translateY(0px);
-o-transform: translateY(0px);
-webkit-transform: translateY(0px);
transform: translateY(0px); }
25% {
-moz-transform: translateY(-3px);
-ms-transform: translateY(-3px);
-o-transform: translateY(-3px);
-webkit-transform: translateY(-3px);
transform: translateY(-3px); }
30% {
-moz-transform: translateY(0px);
-ms-transform: translateY(0px);
-o-transform: translateY(0px);
-webkit-transform: translateY(0px);
transform: translateY(0px); } }
.bounce {
-moz-animation: bounce 2s infinite;
-ms-animation: bounce 2s infinite;
-webkit-animation: bounce 2s infinite;
-o-animation: bounce 2s infinite;
animation: bounce 2s infinite; }
/* Larger than mobile */
/* Larger than phablet (also point when grid becomes active) */
/* Larger than tablet */
/* Larger than desktop */
@media (min-width: 1000px) {
#mobile-svg {display: none; }
#parallax {display: block; }
svg.fish1 { top:5%;}
svg.fish1 { bottom:80%;}
}
@media (max-width: 999px) {
svg.fish1 { top:5%;}
svg.fish2 { bottom:80%;}
#blue {display:none;}
}
/* Larger than Desktop HD */
@media (min-width: 1200px) {
.waves {
bottom: -260px; }
.mountains-pink svg, .mountains-purple svg {
bottom: 5%; }
}
</style>
</head>
<body>
<section id="topper">
<div id="parallax">
<div class="layer background" data-type="parallax" data-depth="0.1"></div>
<div class="layer sun" data-type="parallax" data-depth="0.12">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="-40 0 551.36 248.7">
<g transform="scale(0.5)">
<circle cx="69.12" cy="41.54" r="25.76" transform="translate(-50.63 51.8) rotate(-49.69)" fill="#fbc73a"/>
</g>
</svg>
</div>
<div class="landscape-container">
<div class="layer background-mountains" data-type="parallax" data-depth="0.15">
<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 595.22 277.03">
<defs>
<linearGradient id="linear-gradient" x1="297.61" y1="277.03" x2="297.61" gradientUnits="userSpaceOnUse">
<stop offset="0.62" stop-color="#c9bdde"/>
<stop offset="0.99" stop-color="#a18aab"/>
</linearGradient>
</defs>
<polygon id="Background_Mountains" data-name="Background Mountains" points="35.64 88.56 54.91 96.51 106.55 7.51 179.47 60.09 191.22 39.82 220.57 63.17 290.14 0 360.75 80.34 421.01 25.22 524.08 93.44 594.9 52.91 595.22 275.52 0 277.03 0 118.4 35.64 88.56" fill="url(#linear-gradient)"/>
</svg>
</div>
<div class="layer sky" data-type="parallax" data-depth="0.15">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="-50 0 541.36 158.7">
<g transform="scale(0.7)">
<g class="cloud one">
<path id="Cloud_2" data-name="Cloud 2" d="M134.95,60.76A11.58,11.58,0,0,1,123.4,72.31H110.08l-0.39.41a11.62,11.62,0,0,1-16.87-.41H84.27a11.55,11.55,0,0,1-1.3-23A9.34,9.34,0,0,1,98.7,44.77a8.31,8.31,0,0,1,.58.64A15.19,15.19,0,0,1,114,33.92h0.28A15.19,15.19,0,0,1,129.4,49.06v0.28q0,0.76-.07,1.51A11.56,11.56,0,0,1,134.95,60.76Z" transform="translate(-43.36 -15.58)" fill="#fff"/>
</g>
<g class="cloud two">
<rect x="334.64" y="20.11" width="65.14" height="27.3" rx="13.65" ry="13.65" fill="#fff"/>
<circle cx="355.18" cy="21.18" r="12.04" fill="#fff"/>
<ellipse cx="376.08" cy="20.74" rx="15.8" ry="13.01" fill="#fff"/>
</g>
<g class="cloud one" transform="translate(200 290.5)" >
<rect x="475.78" y="130.14" width="65.57" height="28.56" rx="14.28" ry="14.28" fill="#fff"/>
<circle cx="495.54" cy="134.41" r="10.66" fill="#fff"/>
<ellipse cx="514.36" cy="139.84" rx="18.83" ry="16.08" fill="#fff"/>
</g>
<g class="cloud two">
<rect x="234.01" y="67.44" width="53.6" height="23.35" rx="11.67" ry="11.67" fill="#fff"/>
<ellipse cx="253.76" cy="68.42" rx="12.3" ry="9.2" fill="#fff"/>
<ellipse cx="274.26" cy="79.27" rx="15.39" ry="13.15" fill="#fff"/>
</g>
</g>
</svg>
</div>
<div class="layer mountains-pink" data-type="parallax" data-depth="0.35">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 595.28 273.25">
<g id="Mountain_4" data-name="Mountain 4">
<path d="M440.51,178.84l-39.38-55.29L251.29,395.36a0.8,0.8,0,0,0,.71,1.18H595.28C595.93,396.54,440.51,178.84,440.51,178.84Z" transform="translate(0 -123.55)" fill="#b66586"/>
<path d="M408.53,184.07c7-1.25,15.27,12.69,21.72,10.9,5.22-1.45,1.84-8.07,4.27-12.4,0.86-1.54,5.65-4.2,5.65-4.2l-39-54.81-41.29,75s19.33-15.13,25.53-12C392.4,190.14,400.5,185.49,408.53,184.07Z" transform="translate(0 -123.55)" fill="#fff"/>
<polygon points="401.13 0 404.85 40.59 420.82 70.13 409.37 92.08 435.82 123.08 436.42 174.32 474.49 195.83 467.04 243.3 502.09 273.25 595.28 272.99 401.13 0" opacity="0.3"/>
<path d="M465.1,173.48" transform="translate(0 -123.55)"/>
<polygon points="331 158.41 370.71 137.29 402.58 209.49 412.46 253.34 410.42 272.73 251.5 272.83 324.8 138.08 331 158.41" fill="#060809" opacity="0.3"/>
</g>
<g id="Mountain_4-2" data-name="Mountain 4">
<path d="M485.18,394.36L344.69,197.11l-35.89-50.39L172.25,394.43a0.73,0.73,0,0,0,.64,1.07H484.58A0.73,0.73,0,0,0,485.18,394.36Z" transform="translate(0 -123.55)" fill="#b66586"/>
<path d="M314.76,199.43c6.4-1.14,8.76,7.91,18.19,8.21,6.06,0.19,4-3.21,6.23-7.16,0.78-1.4,5.17-3.84,5.17-3.84l-35.55-49.91c0-1.27-37.68,68.35-37.68,68.35s16.76-13.81,22.41-10.95C299.94,207.36,307.44,200.73,314.76,199.43Z" transform="translate(0 -123.55)" fill="#fff"/>
<polygon points="308.81 23.17 312.06 59.93 317.12 78.23 316.18 106.86 340.29 135.1 326.89 181.38 351.82 194.87 363.95 247.32 401.94 271.96 485.99 271.96 308.81 23.17" opacity="0.3"/>
<path d="M325.84,192.22" transform="translate(0 -123.55)"/>
</g>
<g id="Mountain_1" data-name="Mountain 1">
<polygon points="319.46 273.06 136.3 37.42 0 273.08 319.46 273.06" fill="#b66586"/>
<path d="M144.78,222.75c7-2,15.89,8.36,23.06,7.44,4.41-.56,12.22-13,12.22-13L136.34,161l-38,65.61s15.94-11.11,23.3-8C129.41,221.87,135.73,225.33,144.78,222.75Z" transform="translate(0 -123.55)" fill="#fff"/>
<polygon points="151.29 108.31 126.65 165.82 147.88 213.48 202.33 235.9 186.44 254.47 233.91 272.99 319.46 272.99 136.25 37.31 151.29 108.31" fill="#060809" opacity="0.31"/>
</g>
</svg>
</div>
<div class="layer mountains-purple" data-type="parallax" data-depth="0.45">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 595.28 245.82">
<g id="Mountain_2" data-name="Mountain 2">
<polygon points="450.97 245.07 303.97 83.48 228.03 0 8.14 245.09 450.97 245.07" fill="#6e517a"/>
<path d="M172.2,205s22.67,15.2,33.63,10.54c6.23-2.65,12.37-5.73,19.3-8.44,4.49-1.75,13.94,4.41,18.75,4.39s14.09-6.22,17.68-9.06c3.77-3,20-.76,19-1.88L228,142.75C227.36,143.39,172.2,205,172.2,205Z" transform="translate(0 -142.75)" fill="#fff"/>
<polygon points="450.94 245.08 228.01 0.01 224.77 56.22 250.01 94.02 233.85 149.37 245.8 183.47 224.28 223.96 309.11 245.04 450.94 245.08" fill="#060809" opacity="0.3"/>
</g>
<g id="Mountain_2-2" data-name="Mountain 2">
<polygon points="197.04 245.33 121.49 154.68 82.47 107.86 0 208.55 0 245.34 197.04 245.33" fill="#6e517a"/>
<polygon points="197.03 245.33 82.46 107.86 80.79 139.39 93.76 160.6 85.46 191.65 91.6 210.77 80.54 233.49 124.14 245.31 197.03 245.33" fill="#060809" opacity="0.3"/>
</g>
<g id="Mountain_3" data-name="Mountain 3">
<polygon points="503.48 245.09 393.7 112.47 389.04 114.03 380.7 126.22 364.02 114.82 351.11 122.2 340.4 114.03 324.8 114.61 218.97 245.09 503.48 245.09" fill="#6e517a"/>
<path d="M351.89,265.12c3.75-1.55,10.47-6.55,14.36-5.8,4.29,0.83,8.61,9.09,12.85,10.08,5,1.18,15.7-13.11,15.7-13.11l-33.9-40.6-37.14,42.94s11-1.1,14.06.26C341.93,260.75,348.23,266.63,351.89,265.12Z" transform="translate(0 -142.75)" fill="#fff"/>
<path d="M360.9,215.7l1.46,44.2,12.28,14.5-13.47,29.11,24.09,24.92-3.87,39.95,37.11,19.34h84.93S360.9,215,360.9,215.7Z" transform="translate(0 -142.75)" fill="#060809" opacity="0.3"/>
</g>
<g id="Mountain_5" data-name="Mountain 5">
<polygon points="595.28 245.8 513.77 95.72 463.43 65.48 419.54 114.92 308.81 245.75 595.28 245.8" fill="#6e517a"/>
<path d="M466.06,261.7c6.89,0.28,18.59-11.68,25.2-15,5.74-2.91,23.31-7,22.51-8.19l-50.33-30.34L426.21,250s9.5-2.07,14.48-1.48C448.16,249.42,459,261.41,466.06,261.7Z" transform="translate(0 -142.75)" fill="#fff"/>
<polygon points="463.43 65.44 477.63 93.28 493.17 119.13 473.33 166.65 517.88 211.53 527.06 245.79 595.28 245.82 513.77 95.73 463.43 65.44" fill="#060809" opacity="0.3"/>
</g>
</svg>
</div>
<div class="layer clouds" data-type="parallax" data-depth="0.45">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="-50 0 541.36 298.7">
<g transform="scale(0.7)">
<g class="cloud one">
<rect x="8.21" y="112.85" width="65.14" height="27.3" rx="13.65" ry="13.65" fill="#fff"/>
<ellipse cx="20.26" cy="124.55" rx="16.89" ry="14.94" fill="#fff"/>
<ellipse cx="46.64" cy="113.47" rx="18.14" ry="14.94" fill="#fff"/>
</g>
<g class="cloud two">
.........完整代码请登录后点击上方下载按钮下载查看
















网友评论0