Created
September 5, 2018 18:10
-
-
Save Nemra1/057dc6d68de5b256f653b8582d7427e1 to your computer and use it in GitHub Desktop.
Slide bottom-bar Animation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ul class="slide-bar"> | |
<li>1</li> | |
<li>2</li> | |
<li>3</li> | |
<li>4</li> | |
</ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var $slideWrap = null, | |
$slideItems = null, | |
slideLength = null, | |
slideHeight = null, | |
slideWidth = null, | |
// bar 설정 | |
barBG = null, | |
barHeight = null; | |
$(function () { | |
initSlide(); | |
initSlideCss(); | |
initSlideEvent(); | |
}); | |
function initSlide() { | |
$slideWrap = $('.slide-bar'); | |
$slideItems = $slideWrap.children(); | |
slideLength = $slideItems.length; | |
slideHeight = $slideWrap.height(); | |
slideWidth = 100/slideLength; | |
// bar 설정 | |
barBG = 'black'; | |
barHeight = 10; | |
} | |
function initSlideCss() { | |
$slideWrap.css({ | |
'width' : 100+'%', | |
'position' : 'relative' | |
}); | |
$slideItems.css({ | |
'width' : slideWidth+'%', | |
'float' : 'left' | |
}); | |
$slideWrap.append('<li class="bottom-bar"></li>'); | |
$('.bottom-bar').css({ | |
'position' : 'absolute', | |
'top' : slideHeight, | |
'height' : barHeight+'px', | |
'width' : slideWidth+'%', | |
'background' : barBG | |
}); | |
} | |
function initSlideEvent() { | |
$slideItems.click(function () { | |
var left = $(this).offset().left; | |
moveBar(left); | |
}); | |
} | |
function moveBar(left) { | |
$('.bottom-bar').animate({ | |
'left' : left | |
}, 400); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*{ | |
padding: 0; | |
margin: 0; | |
} | |
.slide-bar{ | |
height: 70px; | |
} | |
.slide-bar li{ | |
list-style:none; | |
line-height: 70px; | |
text-align: center; | |
box-sizing: border-box; | |
border: 1px solid powderblue; | |
background: tomato; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment