μ μκΈ°κ° | 22.06.12 ~ 22.06.14 (3μΌ μμ) |
μ¬μ© μΈμ΄ | html, css, jquery |
μ¬μ© νλ¬κ·ΈμΈ | gsap, swiper |
λΆλ₯ | pc, mobile, ν΄λ‘ μ½λ© |
π¬ μμ
νκΈ° μ μ°μννμ λ€
νμ΄μ§ λ©μΈ μ¬λΌμ΄λλ₯Ό μ΄ν΄λ³Έ κ²°κ³Ό, μ¬λΌμ΄λ 17κ°κ° μλ‘κ³ μΉ¨ ν λ λ§λ€ μ¬λΌμ΄λ 5κ°λ₯Ό μ ννμ¬ λ³΄μ¬μ£Όκ³ μμμ΅λλ€.
π 17κ° μ¬λΌμ΄λλ₯Ό htmlμ μμ±
<section class="swiper sc-mainSlide"> <h2 class="blind">λ©μΈ μ¬λΌμ΄λ</h2> <div class="swiper-wrapper"> <div class="swiper-slide"> <a href="" class="link-slide slide-intro01"> <div class="img-box left"><img src="./assets/images/slide_intro01.jpg" alt="λκ΅°κ° μ§μΌλ³΄κ³ μλ€?"></div> <div class="txt-box"> <span class="default-txt">μ°μννμ λ€μ΄ μκ³ μΆλ€</span> <h3 class="desc">λκ΅°κ°<span class="fiction">μ§μΌλ³΄κ³ μλ€?</span></h3> <span class="cate">νμ¬ μκ° ></span> </div> </a> </div> . . . . . <div class="swiper-slide"> <a href="" class="link-slide slide-more01"> <div class="img-box small"><img src="./assets/images/slide_more01.jpg" alt="μ΄κ² λ¬΄μ¨ μΌμ΄μΌ! 컨νΌλ°μ€"></div> <div class="txt-box black"> <span class="default-txt">μ°μννμ λ€μ΄ μκ³ μΆλ€</span> <h3 class="desc">μ΄κ² λ¬΄μ¨ μΌμ΄μΌ!<br><span class="fiction">컨νΌλ°μ€</span></h3> <span class="cate">μμΈν 보기 ></span> </div> </a> </div> </div> <div class="swiper-pagination"></div> </section>
π λ°°μ΄ μμ±
var numArray = []; var slideArray = [];
π¬ 5κ°μ λμλ₯Ό λ£μ΄ μ€ λ°°μ΄
numArray
μ 5κ°μ μ¬λΌμ΄λλ₯Ό λ£μ΄ μ€ μ¬λΌμ΄λ λ°°μ΄slideArray
λ₯Ό μμ±ν΄μ£Όμμ΅λλ€.
π μ¬λΌμ΄λ λ°°μ΄μ λλ€μΌλ‘ μ¬λΌμ΄λ λ£κΈ°
('.sc-mainSlide .swiper-slide').each(function(){ var randomSlide = Math.floor(Math.random() * 17) + 1; if(!numArray.includes(randomSlide)) { numArray.push(randomSlide); slideArray.push($('.sc-mainSlide .swiper-slide:nth-child('+randomSlide+')').html()); }
π¬ λ°λ³΅λ¬Έμ μ΄μ©νμ¬ μ¬λΌμ΄λ 17κ°μ λ§μΆ° 1~17κΉμ§ λμ κ°μ μμ±νμ¬
randomSlide
λ³μμ λ£μ΄μ£Όμμ΅λλ€.
π¬ μ€λ³΅μ²΄ν¬λ₯Ό ν΄μ£ΌκΈ° μν΄numArray
λ³μ μμ λ°©κΈ μμ±νrandomSlide
κ°μ΄ ν¬ν¨λλμ§ μ‘°κ±΄λ¬Έμ κ±Έμ΄μ£Όκ³ μλ€λ©΄,numArray
λ°°μ΄μrandomSlide
κ°μpush
λ₯Ό μ΄μ©νμ¬ λ£μ΄μ£Όμμ΅λλ€.
π¬ λ§μ°¬κ°μ§λ‘ htmlμrandomSlide
κ° λ²μ§Έ μ¬λΌμ΄λλ₯Ό μ°Ύμ κ·Έ htmlμ ν΅μ§Έλ‘SlideArray
λ°°μ΄μ λ£μ΄μ€λλ€.
π 5κ°μ μ¬λΌμ΄λλ₯Ό λ£μλ€λ©΄?
$('.sc-mainSlide .swiper-slide').each(function(){ if(numArray.length == 5) { $('.sc-mainSlide .swiper-wrapper').empty(); $(numArray).each(function(i){ $('.sc-mainSlide .swiper-wrapper').append('<div class="swiper-slide"></div>') $('.sc-mainSlide .swiper-slide:last-child').append(slideArray[i]); }) } })
π¬ λ§μ½
numArray
μ λ€μ΄μλ λμκ° 5κ°κ° λλ€λ©΄, htmlμ λ€μ΄μλ 17κ°μ μ¬λΌμ΄λλ₯Όempty()
μ μ΄μ©νμ¬ μ λΆ λΉμμ£Όκ³ ,numArray
μ κΈΈμ΄λ§νΌ λ°λ³΅λ¬Έμ λλ € μλ‘μ΄ μ¬λΌμ΄λ μμμ μμ±νκ³ μ μ₯ν΄λSlideArray
μ μ¬λΌμ΄λλ€μappend
λ₯Ό μ΄μ©νμ¬ νλμ© μ±μ λ£μμ΅λλ€.
π μ΅μ’ μ½λ
var numArray = [];
var slideArray = [];
$('.sc-mainSlide .swiper-slide').each(function(){
var randomSlide = Math.floor(Math.random() * 17) + 1;
if(!numArray.includes(randomSlide)) {
numArray.push(randomSlide);
slideArray.push($('.sc-mainSlide .swiper-slide:nth-child('+randomSlide+')').html());
}
if(numArray.length == 5) {
$('.sc-mainSlide .swiper-wrapper').empty();
$(numArray).each(function(i){
$('.sc-mainSlide .swiper-wrapper').append('<div class="swiper-slide"></div>')
$('.sc-mainSlide .swiper-slide:last-child').append(slideArray[i]);
})
}
})
π¬ μ°μννμ λ€
λ©μΈ μ¬λΌμ΄λ μ λͺ© μ€ λμ§Έμ€λΆν° ν κΈμμ© μμ°¨μ μΌλ‘ λνλλ λͺ¨μ΅μ λ³Ό μ μμ΅λλ€.
π ν κΈμμ© λ³΄μ¬μ§ λΆλΆ ν΄λμ€ μ£ΌκΈ°
<h3 class="desc">λκ΅°κ°<span class="fiction">μ§μΌλ³΄κ³ μλ€?</span></h3>
.sc-mainSlide .txt-box .desc .fiction { display: none; }
π¬ λͺ¨λ μ¬λΌμ΄λλ§λ€ ν κΈμμ© λ³΄μ¬μ§ λΆλΆμ
class="fiction
μΌλ‘ μ€μ νμ¬ λ°λ‘ ꡬλΆνμκ³ ,display:none
μ νμμ΅λλ€.
π ν κΈμμ© μλΌμ htmlμ λ£κΈ°
var text = $('.swiper-slide-active').find('.fiction').text().split(""); $('.swiper-slide-active').find('.desc').append('<span class="fade"></span>') $(text).each(function(i){ $('.swiper-slide-active').find('.fade').append('<i class="fade-txt'+i+'">'+text[i]+'</i>'); })
π¬ htmlμμ
fiction
ν΄λμ€λ₯Ό μ°Ύμ ν μ€νΈλ₯Όsplit("")
μ μ΄μ©νμ¬ ν κΈμμ© μλΌtext
λ³μμ λ£μ΄μ£Όμμ΅λλ€.
π¬ κ·Έ ν, νμ±νλ μ¬λΌμ΄λ.swiper-slide-active
μμ μ λͺ© λΆλΆ λ€μfade
ν΄λμ€λ₯Ό κ°μ§span
νκ·Έλ₯Όappend
μ μ΄μ©νμ¬ λ£μ΄μ£Όμμ΅λλ€.
π¬ μλ₯Έtext
μ κΈΈμ΄ λ§νΌ λ°λ³΅λ¬Έμ λλ €fade
ν΄λμ€λ₯Ό κ°μ§span
νκ·Έμfade-txt
ν΄λμ€λ₯Ό κ°μ§i
νκ·Έλ‘ κΈμ νλνλ μΆκ°νμμ΅λλ€.
π setIntervalλ‘ opacity μ‘°μ νκΈ°
var i = 0; setInterval(function(){ if(i < text.length) { $('.swiper-slide-active').find('.fade-txt'+i+'').animate({opacity: "1"}); i++; } else { return false; } }, 200)
π¬
fade-txt
μ μμλ₯Ό μ‘μμ£ΌκΈ° μν΄ i λ³μλ₯Ό μμ±νμ¬ 0μΌλ‘ μ΄κΈ°ν ν΄μ£Όκ³ , 0.2sλ‘ μλνλ setIntervalμ μμ±,text
μ κΈΈμ΄λ§νΌfade-txt
μi
λ²μ§Έ μμλ₯Όopacity:1
λ‘ λ³κ²½ν΄ μ€ νi++
μ ν΄μ£Όμκ³ ,i
κ°text
μ κΈΈμ΄λ³΄λ€ λμμ§κ² λλ©΄ setIntervalμ μ’ λ£ν΄μ£Όμμ΅λλ€.
π μ¬λΌμ΄λκ° λμ΄κ° λλ§λ€ μλ
function fadeText() { $('.swiper-slide .fade').remove(); var text = $('.swiper-slide-active').find('.fiction').text().split(""); $('.swiper-slide-active').find('.desc').append('<span class="fade"></span>') $(text).each(function(i){ $('.swiper-slide-active').find('.fade').append('<i class="fade-txt'+i+'">'+text[i]+'</i>'); }) var i = 0; setInterval(function(){ if(i < text.length) { $('.swiper-slide-active').find('.fade-txt'+i+'').animate({opacity: "1"}); i++; } else { return false; } }, 200) }
π¬ μ΅μ’ μ μΌλ‘ μμ±ν μ΄ μ½λλ₯Ό
fadeText()
λΌλ λ³μλͺ μΌλ‘ ν¨μλ₯Ό λ§λ€μ΄μ£Όκ³ , μ¬λΌμ΄λκ° λ³κ²½λ λλ§λ€fade
ν΄λμ€λ₯Ό κ°μ§span
νκ·Έκ° μμ±λ ν λ ν¨μ μμνμλ§μremove
λ‘ μ΄κΈ°νλ₯Ό ν΄μ£Όλ μ½λλ₯Ό μΆκ°νμμ΅λλ€.on: { slideChange: function(){ setTimeout(function(){ fadeText(); }) } },
π¬ λ©μΈμ¬λΌμ΄λ
swiper
μμSlideChange
λ©μλλ₯Ό μ΄μ©ν΄setTimeout
μΌλ‘fadeText()
ν¨μλ₯Ό μ€ννμμ΅λλ€.
β λ¬Έμ μ λ°μ
π¬ μ΄λ κ² ν κ²°κ³Ό μ¬λΌμ΄λκ° λμ΄κ° λ μνλ λλ‘ μ μλνμ§λ§ λΉ λ₯΄κ² λκΈΈ λ μ΄λ―Έ μ€νλfadeText()
μ μ¬λΌμ΄λκ° λμ΄κ°μ μ€νλfadeText()
κ° κ²Ήμ³μ μ μ©λλ λ¬Έμ μ μ΄ λ°μνμμ΅λλ€.
π μμ
π¬ μ΄λ₯Ό μμ νκΈ° μν΄μ μ¬λΌμ΄λκ° λμ΄κ° λ μ΄λ―Έ μ€νλκ³ μλfadeText()
ν¨μλ₯Ό μ’ λ£νλ λ©μλλ₯Ό λ£μ΄μΌ νλ€κ³ μκ°νμ΅λλ€.var isStop = false; var textAni = setInterval(function(){ if(!isStop) { if(i < text.length) { $('.swiper-slide-active').find('.fade-txt'+i+'').animate({opacity: "1"}); i++; } else { return false; } } else { clearInterval(textAni); isStop = false; fadeText(); } }, 200) -------------------------------------------------------------------------------------------- on: { slideChange: function(){ isStop = true; } },
π¬ κ·Έλμ
isStop
μ΄λΌλ λ³μλ₯Ό μμ±νμ¬false
λ‘ λ΄κ³ ,opacity
κ° μ‘°μ λλsetInteval
μ λ³μtextAni
λ‘ μ€μ ν΄ μ€ ν,isStop
μ΄false
μΈ κ²½μ° ν¨μκ° μ€νλκ² μ μ©νκ³true
μΈ κ²½μ°textAni
κ° μ’ λ£λκ²clearInterval
μ μ¬μ©νκ³ ,isStop = false
λ‘ λ³κ²½ν νfadeText()
λ₯Ό μ μ©νκ² νμμ΅λλ€.
π¬swiper
μslideChange
λ©μλμλ μ¬λΌμ΄λκ° λ³κ²½λ λisStop = true
λ‘ λ³κ²½νμ¬ κ·Έ μ¦μfadeText()
ν¨μκ° μ’ λ£λκ² λ§λ€μ΄μ λ¬Έμ μ μ ν΄κ²°ν μ μμμ΅λλ€!
π μ΅μ’ μ½λ
var isStop = false;
function fadeText() {
$('.swiper-slide .fade').remove();
var text = $('.swiper-slide-active').find('.fiction').text().split("");
$('.swiper-slide-active').find('.desc').append('<span class="fade"></span>')
$(text).each(function(i){
$('.swiper-slide-active').find('.fade').append('<i class="fade-txt'+i+'">'+text[i]+'</i>');
})
var i = 0;
var textAni = setInterval(function(){
if(!isStop) {
if(i < text.length) {
$('.swiper-slide-active').find('.fade-txt'+i+'').animate({opacity: "1"});
i++;
} else {
return false;
}
} else {
clearInterval(textAni);
isStop = false;
fadeText();
}
}, 200)
}
----------------------------------------------------------------------------------------------------
var mainSlide = new Swiper(".sc-mainSlide", {
pagination: {
el: ".swiper-pagination",
},
autoplay: {
delay: 7000,
},
on: {
slideChange: function(){
isStop = true;
}
},
loop: true
});
π¬ μ°μννμ λ€
νμ΄μ§ νλ¨ κΈκΌ΄ λΆλΆμμ 컨ν
μΈ λ€μ΄ λμ΄μ§ μκ³ κ³μν΄μ μμΌλ‘ λ‘€λ§λλ λͺ¨μ΅μ λ³Ό μ μμμ΅λλ€.
π slide-font html μμ±
<div class="slide-font"> <ul class="font-area"> <li class="font-item hanna11"><h3 class="font-title">νλλμ΄νμ΄μ²΄</h3></li> <li class="font-item jua"><h3 class="font-title">μ£Όμ체</h3></li> <li class="font-item dohyeon"><h3 class="font-title">λν체</h3></li> <li class="font-item yeonsung"><h3 class="font-title">μ°μ±μ²΄</h3></li> <li class="font-item kiranghaerang"><h3 class="font-title">κΈ°λν΄λ체</h3></li> <li class="font-item hannaAir"><h3 class="font-title">νλ체 Air</h3></li> <li class="font-item hannaPro"><h3 class="font-title">νλ체 Pro</h3></li> <li class="font-item euljiro"><h3 class="font-title">μμ§λ‘체</h3></li> <li class="font-item euljiro10year"><h3 class="font-title">μμ§λ‘ 10λ ν체</h3></li> <li class="font-item euljiroorae"><h3 class="font-title">μμ§λ‘ μ€λμ€λ체</h3></li> </ul> </div>
π¬ htmlμλ scriptλ‘ λ³΅μ νκΈ° μν΄μ ν λ©μ΄λ¦¬λ§ μμ±νμμ΅λλ€.
π font-area
clone()
μ μ΄μ©νμ¬ λ³΅μ /μΆκ°var fontItemClone = $('.font-area').clone(); fontItemClone.addClass('dup'); $('.slide-font').append(fontItemClone);
π¬
fontItemClone
λ³μλ₯Ό λ§λ€μ΄ font 컨ν μΈ λ€μclone()
μ μ΄μ©νμ¬ λ³΅μ ν΄ λ£μ΄μ£Όμκ³dup
ν΄λμ€λ₯Ό μΆκ°νμ¬ μ΅μ’ λΆλͺ¨μΈslide-font
λ€μ μΆκ°νμμ΅λλ€
π
keyframe
μ μ΄μ©νμ¬ λ¬΄νλ‘€λ§.sc-font .font-area { display: inline-flex; animation: fontSlide 40s linear infinite; } .sc-font .font-area.dup { animation: fontSlideDup 40s linear infinite; } ---------------------------------------------------------------------- @keyframes fontSlide { 0% { transform: translateX(0); } 50% { transform: translateX(-100%); } 50.01%{ transform: translateX(100%); } 100%{ transform: translateX(0); } } @keyframes fontSlideDup { 0% { transform: translateX(0); } 100% { transform: translateX(-200%); } }
π¬ μλ μλ
font-area
λfontSlide
keyframeμΌλ‘ μ λλ©μ΄μ μ μ λ°λμ XμΆμΌλ‘ -100%λ‘ μ΄λνκ² νμ¬ νλ©΄μ μ보μ¬μ§ λ λ°λ‘ XμΆ 100%λ‘ μ΄λνμ¬ λ€μ 0μΌλ‘ μ€μ ν΄ μ μλ¦¬κ³ λμμ€κ² λ§λ€μμ΅λλ€.
π¬ 볡μ λ.dup
μfontSlideDup
keyframμΌλ‘ XμΆ -200%λ‘ μ€μ νμ¬ μμ°μ€λ½κ² 무νλ‘€λ§μ΄ λλλ‘ μμ±νμμ΅λλ€!