Создаем разметку HTML:
Пишем стиль:
Пишем jquery:
Смотрим результат:
HTML:
<div id="hero">
<div id="carousel">
<div id="bg">
<div class="inner">
<svg class="shield" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 85.14 109.17"><path d="M82.79,8.63S70,0,42.65,0h-.16C15.11,0,2.35,8.63,2.35,8.63S-4.18,44.74,4.53,71c6.6,19.86,35.3,36.65,38,38.22C45.31,107.6,74,90.81,80.61,71,89.32,44.74,82.79,8.63,82.79,8.63Z"/></svg>
<svg class="shield-shadow" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 85.14 109.17"><path d="M82.79,8.63S70,0,42.65,0h-.16C15.11,0,2.35,8.63,2.35,8.63S-4.18,44.74,4.53,71c6.6,19.86,35.3,36.65,38,38.22C45.31,107.6,74,90.81,80.61,71,89.32,44.74,82.79,8.63,82.79,8.63Z"/></svg>
</div>
</div>
<a id="stark" class="item hidden" href="http://gameofthrones.wikia.com/wiki/House_Stark" target="_blank">
<span class="inner">
<span class="img">
<svg class="blazon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 165.08 119.43"></svg>
<svg class="blazon-shadow" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 165.08 119.43"></svg>
</span>
<span class="txt">
<span class="line-1">WINTER IS COMING</span>
<span class="line-2">STARK</span>
</span>
</span>
</a>
<a id="lannister" class="item hidden" href="http://gameofthrones.wikia.com/wiki/House_Lannister" target="_blank">
<span class="inner">
<span class="img">
<svg class="blazon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 147.84 197.75"></svg>
<svg class="blazon-shadow" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 147.84 197.75"></svg>
</span>
<span class="txt">
<span class="line-1">Hear me roar</span>
<span class="line-2">Lannister</span>
</span>
</span>
</a>
<a id="greyjoy" class="item hidden" href="http://gameofthrones.wikia.com/wiki/House_Greyjoy" target="_blank">
<span class="inner">
<span class="img">
<svg class="blazon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 149.65 133.2"></svg>
<svg class="blazon-shadow" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 149.65 133.2"></svg>
</span>
<span class="txt">
<span class="line-1">We do not sow</span>
<span class="line-2">Greyjoy</span>
</span>
</span>
</a>
<a id="tyrell" class="item hidden" href="http://gameofthrones.wikia.com/wiki/House_Tyrell" target="_blank">
<span class="inner">
<span class="img">
<svg class="blazon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 148.58 144.43"></svg>
<svg class="blazon-shadow" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 148.58 144.43"></svg>
</span>
<span class="txt">
<span class="line-1">Growing strong</span>
<span class="line-2">Tyrell</span>
</span>
</span>
</a>
<a id="targaryen" class="item hidden" href="http://gameofthrones.wikia.com/wiki/House_Targaryen" target="_blank">
<span class="inner">
<span class="img">
<svg class="blazon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 160.24 166.1"></svg>
<svg class="blazon-shadow" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 160.24 166.1"></svg>
</span>
<span class="txt">
<span class="line-1">Fire and blood</span>
<span class="line-2">Targaryen</span>
</span>
</span>
</a>
<a id="arryn" class="item hidden" href="http://gameofthrones.wikia.com/wiki/House_Arryn" target="_blank">
<span class="inner">
<span class="img">
<svg class="blazon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 137.02 137.05"></svg>
<svg class="blazon-shadow" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 137.02 137.05"></svg>
</span>
<span class="txt">
<span class="line-1">As high as honor</span>
<span class="line-2">Arryn</span>
</span>
</span>
</a>
<a id="baratheon" class="item hidden" href="http://gameofthrones.wikia.com/wiki/House_Baratheon" target="_blank">
<span class="inner">
<span class="img">
<svg class="blazon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 159.38 226.2"></svg>
<svg class="blazon-shadow" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 159.38 226.2"></svg>
</span>
<span class="txt">
<span class="line-1">Ours is the fury</span>
<span class="line-2">Baratheon</span>
</span>
</span>
</a>
<a id="martell" class="item hidden" href="http://gameofthrones.wikia.com/wiki/House_Martell" target="_blank">
<span class="inner">
<span class="img">
<svg class="blazon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 167.67 167.67"></svg>
<svg class="blazon-shadow" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 167.67 167.67"></svg>
</span>
<span class="txt">
<span class="line-1">Undowed Unbent Unbroken</span>
<span class="line-2">Martell</span>
</span>
</span>
</a>
<a id="tully" class="item hidden" href="http://gameofthrones.wikia.com/wiki/House_Tully" target="_blank">
<span class="inner">
<span class="img">
<svg class="blazon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 156.47 72.61"></svg>
<svg class="blazon-shadow" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 156.47 72.61"></svg>
</span>
<span class="txt">
<span class="line-1">Family Duty Honor</span>
<span class="line-2">Tully</span>
</span>
</span>
</a>
</div>
</div><!-- /hero -->
Less:
// ------------------ RESET ------------------
* { -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; }
html, body{ border:0; font-size:16px; line-height:1.5; margin:0; padding:0 }
a img{ border:0 }
// ------------------ FONT-FACE ------------------
@import url('https://fonts.googleapis.com/css?family=Neuton:200,400');
// ------------------ STYLES ------------------
#hero {
display: flex;
justify-content: center;
align-items: center;
width: 100vw;
height: 100vh;
padding: 50px;
background: #1d1d1d;
overflow: hidden;
#carousel:hover #bg .inner .shield {
transition: fill 0.2s linear;
}
&.stark {
@shield: #fdf6d6;
@shieldH: #fff;
@txt1: #7e817f;
@txt1H: #60aca8;
@txt2: #040707;
#carousel #bg .inner .shield {fill: @shield;}
#carousel:hover #bg .inner .shield {fill: @shieldH;}
#carousel .item .line-1 {color: @txt1;}
#carousel:hover .item .line-1 {color: @txt1H;}
#carousel .item .line-2 {color: @txt2;}
#carousel .item .inner .img {width: 110%;}
#carousel .item .inner .img svg {top: 0;}
}
&.lannister {
@shield: #a01830;
@shieldH: #9f001c;
@txt1: #f7e26a;
@txt1H: #ffc13c;
@txt2: #ffffff;
#carousel #bg .inner .shield {fill: @shield;}
#carousel:hover #bg .inner .shield {fill: @shieldH;}
#carousel .item .line-1 {color: @txt1;}
#carousel:hover .item .line-1 {color: @txt1H;}
#carousel .item .line-2 {color: @txt2;}
#carousel .item .inner .img {width: 73%;}
#carousel .item .inner .img svg {top: -20%;}
}
&.greyjoy {
@shield: #101006;
@shieldH: #1b2225;
@txt1: #f8d63c;
@txt1H: #fffa72;
@txt2: #ffffff;
#carousel #bg .inner .shield {fill: @shield;}
#carousel:hover #bg .inner .shield {fill: @shieldH;}
#carousel .item .line-1 {color: @txt1;}
#carousel:hover .item .line-1 {color: @txt1H;}
#carousel .item .line-2 {color: @txt2;}
#carousel .item .inner .img {width: 100%;}
#carousel .item .inner .img svg {top: -10%;}
}
&.targaryen {
@shield: #11120b;
@shieldH: #261a1a;
@txt1: #9f1c2e;
@txt1H: #ff0018;
@txt2: #fff;
#carousel #bg .inner .shield {fill: @shield;}
#carousel:hover #bg .inner .shield {fill: @shieldH;}
#carousel .item .line-1 {color: @txt1;}
#carousel:hover .item .line-1 {color: @txt1H;}
#carousel .item .line-2 {color: @txt2;}
#carousel .item .inner .img {width: 85%;}
#carousel .item .inner .img svg {top: -10%;}
}
&.tyrell {
@shield: #9bb693;
@shieldH: #5f8853;
@txt1: #fbd343;
@txt1H: #c7e82d;
@txt2: #040707;
#carousel #bg .inner .shield {fill: @shield;}
#carousel:hover #bg .inner .shield {fill: @shieldH;}
#carousel .item .line-1 {color: @txt1;}
#carousel:hover .item .line-1 {color: @txt1H;}
#carousel .item .line-2 {color: @txt2;}
#carousel .item .inner .img {width: 85%;}
#carousel .item .inner .img svg {top: -10%;}
}
&.tully {
@shield: #002b4b;
@shieldH: #00376a;
@txt1: #821528;
@txt1H: #9e0722;
@txt2: #fff;
#carousel #bg .inner .shield {fill: @shield;}
#carousel:hover #bg .inner .shield {fill: @shieldH;}
#carousel .item .line-1 {color: @txt1;}
#carousel:hover .item .line-1 {color: @txt1H;}
#carousel .item .line-2 {color: @txt2;}
#carousel .item .inner .img {width: 110%;}
#carousel .item .inner .img svg {top: 15%;}
}
&.martell {
@shield: #f38c01;
@shieldH: #f8bd1f;
@txt1: #872921;
@txt1H: #a13506;
@txt2: #fff;
#carousel #bg .inner .shield {fill: @shield;}
#carousel:hover #bg .inner .shield {fill: @shieldH;}
#carousel .item .line-1 {color: @txt1;}
#carousel:hover .item .line-1 {color: @txt1H;}
#carousel .item .line-2 {color: @txt2;}
#carousel .item .inner .img {width: 83%;}
#carousel .item .inner .img svg {top: -8%;}
}
&.arryn {
@shield: #002b4b;
@shieldH: #004461;
@txt1: #fbf4c8;
@txt1H: #fff;
@txt2: #fff;
#carousel #bg .inner .shield {fill: @shield;}
#carousel:hover #bg .inner .shield {fill: @shieldH;}
#carousel .item .line-1 {color: @txt1;}
#carousel:hover .item .line-1 {color: @txt1H;}
#carousel .item .line-2 {color: @txt2;}
#carousel .item .inner .img {width: 82%;}
#carousel .item .inner .img svg {top: -7%;}
}
&.baratheon {
@shield: #fcb600;
@shieldH: #ffce23;
@txt1: #5a4032;
@txt1H: #7e5805;
@txt2: #100a09;
#carousel #bg .inner .shield {fill: @shield;}
#carousel:hover #bg .inner .shield {fill: @shieldH;}
#carousel .item .line-1 {color: @txt1;}
#carousel:hover .item .line-1 {color: @txt1H;}
#carousel .item .line-2 {color: @txt2;}
#carousel .item .inner .img {width: 73%;}
#carousel .item .inner .img svg {top: -20%;}
}
#carousel-nav {
position: absolute;
z-index: 2;
left: 50%;
bottom: 50px;
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
width: 100%;
transform: translateX(-50%);
button {
display: block;
width: 60px;
margin: 0 15px;
padding: 0;
background: none;
border-radius: 50%;
border: none;
cursor: pointer;
opacity: 0.2;
transition: opacity 0.2s linear;
&:hover {
opacity: 0.6;
}
&.active {
opacity: 1;
}
}
@media screen and (max-height: 800px){
left: auto;
right: 20px;
top: 50%;
bottom: auto;
flex-direction: column;
flex-wrap: wrap;
align-content: end;
width: auto;
height: 100%;
transform: translate(0, -50%);
button {
width: 30px;
margin: 10px;
}
}
}
#carousel-wp {
position: absolute;
z-index: 0;
left: 0;
top: 0;
width: 100vw;
height: 100vh;
overflow: hidden;
img {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
min-width: 100%;
min-height: 100%;
display: block;
opacity: 0;
transition: opacity 0.6s linear;
&.active {
opacity: 1;
transition: opacity 0.8s linear 0.2s;
}
}
}
#carousel {
position: relative;
z-index: 1;
display: block;
width: 60vh;
max-width: 400px;
margin-top: 10vh;
perspective: 1000px;
transform-style: preserve-3d;
&:before {
content: "";
display: block;
padding-top: 130%;
}
#bg {
position: absolute;
z-index: 1;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
width: 100%;
height: 100%;
transform-style: preserve-3d;
.inner {
width: 100%;
height: 100%;
transform: translateZ(0);
transform-style: preserve-3d;
.shield {
position: absolute;
left: 50%;
top: 50%;
display: block;
width: 100%;
fill: #666;
transform: translateX(-50%) translateY(-50%);
transition: fill 0.8s linear;
}
.shield-shadow {
position: absolute;
left: 50%;
top: 50%;
display: block;
width: 100%;
border-radius: 50%;
opacity: 0.5;
filter: blur(40px);
transform: translateX(-50%) translateY(-50%) translateZ(-300px) scale(1.2);
}
&.reset {
transform: rotateX(0) rotateY(0) !important;
transition: transform 1s ease-out 0.4s;
}
}
}
.item {
position: absolute;
z-index: 2;
left: 50%;
top: 50%;
display: block;
width: 100%;
height: 100%;
transform: translate(-50%, -50%);
transform-style: preserve-3d;
text-decoration: none;
&.hidden {
opacity: 0;
visibility: hidden;
}
.inner {
position: relative;
display: flex;
flex-direction: column;
justify-content: flex-start;
align-items: center;
width: 100%;
height: 100%;
transform: translateZ(0);
transform-style: preserve-3d;
&.reset {
transform: rotateX(0) rotateY(0) !important;
transition: transform 1s ease-out 0.4s;
}
.img {
position: relative;
width: 100%;
height: 63%;
transform-style: preserve-3d;
svg {
position: absolute;
left: 0;
top: 0;
display: block;
width: 100%;
&.blazon {
transform: translateZ(80px);
}
&.blazon-shadow {
opacity: 0.1;
transform: translateZ(0px) scale(1.1);
}
}
}
.txt {
display: block;
transform-style: preserve-3d;
transform: translateZ(50px);
text-align: center;
font-family: "Neuton", sans-serif;
font-size: 80px;
font-size: 10vh;
text-transform: uppercase;
line-height: 1;
color: #32325D;
white-space: nowrap;
transition: transform 0.3s ease-out;
span {
display: block;
&.line-1 {
font-weight: 200;
transition: color 0.4s linear;
}
&.line-2 {
transform: translateZ(-20px);
font-size: 0.5em;
font-weight: 400;
}
}
}
}
&:hover {
.txt {
transform: translateY(-30%) translateZ(120px);
transition: transform 0.4s ease-out;
}
}
}
}
}
JavaScript:
// Variables globales
var carouselMasterTl = null;
var carouselItemIsHover = false;
var carouselItemPauseDuration = 2;
var imgDataString = "";
var imgData = {};
// **** Initialisation des fonctions **** //
$(function () {
carousel3dFx();
getImgData(function(response){
imgDataString = response.replace(/"/g, "\\\"").replace(/'/g, "\"");
imgData = JSON.parse(imgDataString);
carouselSlider();
});
});
// ************************************** //
function getImgData(callback){
$.ajax({
type: "GET",
dataType: "text",
url: "https://gist.githubusercontent.com/Cedrickdai/b0bce8279dacfe336ccad3bf72285500/raw/8262dd18744abd0e63f1f07e63e283037b23df1f/codepen-GoT-imgData.txt",
success: callback,
error: function(response){console.log("error");}
});
}
function carousel3dFx(){
var el = $("#bg .inner, .item .inner");
$(document).on("mousemove",function(e) {
var ax = -($("#hero").innerWidth()/2- e.pageX)/35;
var ay = ($("#hero").innerHeight()/2- e.pageY)/25;
el.removeClass("reset").attr("style", "transform: rotateY("+ax+"deg) rotateX("+ay+"deg);-webkit-transform: rotateY("+ax+"deg) rotateX("+ay+"deg);-moz-transform: rotateY("+ax+"deg) rotateX("+ay+"deg)");
})
.on("mouseout",function(e) {
el.addClass("reset");
});
}
function carouselSlider(){
carouselMasterTl = new TimelineMax({repeat: -1});
// $("#carousel .item").hover(function(){carouselItemIsHover = true;},function(){carouselItemIsHover = false; carouselMasterTl.resume();});
$("#carousel").parent().append('<div id="carousel-nav"></div><div id="carousel-wp"></div>');
$("#carousel .item").each(function(i){
var thisId = $(this).attr("id");
// console.log(thisId);
var splitText = new SplitText("#"+thisId+" .txt", {type:"chars"});
var line1Chars = $("#"+thisId+" .txt .line-1 div");
var line1EvenChars = getEvenInArray(line1Chars);
var line1OddChars = getOddInArray(line1Chars);
var introTimeline = getIntroTimeline(thisId, line1OddChars, line1EvenChars);
var outroTimeline = getOutroTimeline(thisId);
carouselMasterTl.add(introTimeline, "intro-"+ thisId);
carouselMasterTl.add(outroTimeline, "outro-"+ thisId);
if(imgData[thisId]){
$(this).find(".blazon").html(thisId +imgData[thisId].blazon);
$(this).find(".blazon-shadow").html(thisId +imgData[thisId].shadow);
$("#carousel-wp").append('<img id="wp-'+ thisId +'" src="'+ imgData[thisId].wp +'"></img>');
$("#carousel-nav").append('<button id="goto-'+ thisId +'">'+ imgData[thisId].icon +'</button>');
}
else{
$("#carousel-nav").append('<button id="goto-'+ thisId +'">'+thisId+'</button>');
}
$("#goto-"+ thisId).click(function(){
carouselMasterTl.seek("intro-"+ thisId);
});
});
}
function getEvenInArray(a) {
var ar = [];
for (var i = 0; i < a.length; i++) {
if(i % 2 === 0) { // index is even
ar.push(a[i]);
}
}
return ar;
}
function getOddInArray(a) {
var ar = [];
for (var i = 0; i < a.length; i++) {
if(i % 2 === 1) { // index is even
ar.push(a[i]);
}
}
return ar;
}
function getIntroTimeline(thisId, line1OddChars, line1EvenChars){
var introTl = new TimelineMax();
introTl.eventCallback("onStart", function(){
$("#carousel-nav button").removeClass("active");
$("#carousel-nav button#goto-"+ thisId).addClass("active");
$("#carousel-wp img").removeClass("active");
$("#carousel-wp img#wp-"+ thisId).addClass("active");
$("#hero").removeClass("arryn baratheon greyjoy lannister stark targaryen tully martell tyrell");
$("#hero").addClass(thisId);
});
introTl.eventCallback("onComplete", function(){
if (carouselItemIsHover) {
carouselMasterTl.pause();
}
});
function getStaggerline1(line1OddChars, line1EvenChars){
var tl = new TimelineMax();
tl.staggerFrom(line1OddChars, 1.4, {
opacity: 0,
scale: 5,
y: "+=200",
ease: Power4.easeOut,
// delay: 0.2,
}, 0.2)
.staggerFrom(line1EvenChars, 0.8, {
opacity: 0,
y: "-=180",
scale: 2,
ease: Power4.easeOut,
}, 0.2, 0);
return tl;
}
introTl.set($("#"+ thisId), {
opacity: 1,
visibility: "visible",
})
.from($("#"+ thisId +" .img .blazon"), 1, {
opacity: 0,
y: "-=250",
scale: 0.4,
rotationX: "+=50deg",
ease: Power4.easeOut,
})
.from($("#"+ thisId +" .img .blazon-shadow"), 0.8, {
opacity: 0,
y: "-=100",
scale: 0.7,
ease: Power4.easeOut,
}, "-=0.8")
.from($("#"+ thisId +" .txt .line-2"), 1.6, {
opacity: 0,
scale: 0.3,
y: "+=150",
rotationX: "-=50deg",
ease: Power4.easeOut,
}, "-=0.8")
.add(getStaggerline1(line1OddChars, line1EvenChars))
.set({}, {}, "+="+ (carouselItemPauseDuration || 3));
return introTl;
}
function getOutroTimeline(thisId){
var outroTl = new TimelineMax();
outroTl.to($("#"+ thisId +" .txt .line-2"), 0.6, {
opacity: 0,
y: "+=80",
rotationX: "-=50deg",
ease: Power3.easeIn,
})
.to($("#"+ thisId +" .txt .line-1"), 0.6, {
opacity: 0,
y: "+=80",
rotationX: "-=20deg",
ease: Power3.easeIn,
}, "-=0.4")
.to($("#"+ thisId +" .img .blazon-shadow"), 0.5, {
opacity: 0,
ease: Power3.easeIn,
}, "-=0.7")
.to($("#"+ thisId +" .img .blazon"), 1, {
y: "+=500",
scale: 0.8,
rotationX: "-=50deg",
ease: Power3.easeIn,
}, "-=0.4")
.to($("#"+ thisId +" .img .blazon"), 0.4, {
opacity: 0,
ease: Power0.easeNone,
}, "-=0.5")
.set($("#"+ thisId), {
opacity: 0,
visibility: "hidden",
});
return outroTl;
}