I have tried to modify this jQuery slider solution: https://stackoverflow.com/a/9864636/908491 (using the first solution - http://jsfiddle.net/sg3s/rs2QK/).
Here is my jsFiddle: http://jsfiddle.net/markrummel/KSHSX/.
The DIV sliding in works just fine, but the one being slid out jumps away, instead of sliding out smoothly at the same rate as the DIV sliding in. I have commented out .hide()
in the javascript and overflow:hidden
in the CSS, so that I could see where the DIV being slid out goes.
This is my first time using .animate()
, so any help you can offer is greatly appreciated!
Here is my javascript:
$('.date-nav-prev').click(function () {
$('.date-nav-next').show();
var current = $('.visible-actions');
var prev = current.prev('.user-actions');
current.removeClass('visible-actions').animate({
left: current.width()
}, 500, function() {
//current.hide();
});
prev.addClass('visible-actions').show().css({
left: -(prev.width())
}).animate({
left: 0
}, 500);
});
$('.date-nav-next').click(function () {
var current = $('.visible-actions');
var next = current.next('.user-actions');
current.removeClass('visible-actions').animate({
left: -(current.width())
}, 500, function() {
//current.hide();
});
next.addClass('visible-actions').show().css({
left: prev.width()
}).animate({
left: 0
}, 500);
});
HTML:
<button class="date-nav-prev">< Prev</button>
<button class="date-nav-next">Next ></button><br />
<div id="wrapper">
<div class="user-actions daysAgo2">
Actions from 2 Days Ago</div>
<div class="user-actions yesterday">
Yesterday's Actions</div>
<div class="user-actions today visible-actions">
Today's Actions</div>
</div>
CSS:
.user-actions.yesterday, .user-actions.daysAgo2, .date-nav-next {display:none;}
#wrapper{width:250px; height:300px; border:1px solid #333;position:relative; float:left;
/*overflow:hidden;*/
}
.user-actions {width:100%; height:100%; position:relative; float:left; overflow:hidden; margin:0;}
.today {background:green;}
.yesterday {background:yellow;}
.daysAgo2 {background:orange;}