I want to limit max height of animation when using arrows to switch. Trying to write a function, that will calculat height of div and +- step in px. But it’s now writed to variable.
var maxfloorh = $('.floor-switch').height();
var actualh = $('.floor-switch').height();
$('.floor-switch li').click(function() {
$('#line').animate({
top: $(this).position().top
});
});
function floorarrs(numbr) {
switch (numbr) {
case 1:
//check here maxfloorh
$('#line').animate({
top: '-=18'
}, 400, function() {
maxfloorh-'18';
console.log(maxfloorh);
});
break
case 2:
//check here maxfloorh
$('#line').animate({
top: '+=18'
}, 400, function() {
maxfloorh+'18';
console.log(maxfloorh);
});
break
}
}
$('.arrw-up').click(function() {
floorarrs(1);
});
$('.arrw-dwn').click(function() {
floorarrs(2);
});
HTML:
<div id="floors" style="margin:60px;">
<div class="arrw-up"></div>
<div class="floor-switch">
<div id='line'></div>
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
</ul>
</div>
<div class="arrw-dwn"></div>
</div>
Here is the working fiddle
I have changed the logic in your arrow
clickfunction, In css the initialtopattribute of the element withid=lineis set to0px…Now whenever the
top = 0px-> the div is on 1stlihence the function is not executed ans so for the down arrow…Note: This may note be the best solution but it’s one of the solutions