Skip to content

Instantly share code, notes, and snippets.

@Nemra1
Created September 5, 2018 18:10
Show Gist options
  • Save Nemra1/057dc6d68de5b256f653b8582d7427e1 to your computer and use it in GitHub Desktop.
Save Nemra1/057dc6d68de5b256f653b8582d7427e1 to your computer and use it in GitHub Desktop.
Slide bottom-bar Animation
<ul class="slide-bar">
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
</ul>
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);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
*{
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