I am trying to make a carousel of sorts. I am kind of stuck with hiding and displaying the next and precious buttons once a div moves to the far left and right of its container.
I think i have everything correct regarding calculating the widths but for some reason when you click the buttons, elements stay hidden irrespective of the conditional comments which should dictate when they should be hidden or shown.
<script type="text/javascript">
$
(document).ready(function () {
//Check width of Gallery div
var galleryWidth = $("#Gallery").innerWidth();
//Check width of GalleryItem
var galleryItemWidth = $(".GalleryItem").innerWidth();
//Check distance from left
var position = $('.GalleryItem').position();
var galleryItemLeft = position.left;
$
(".MoveRight").click(function () {
$
(".GalleryItem").animate({
"left": "+=50px"
}, "slow");
$
(".GalleryItem2").animate({
"left": "+=100px"
}, "slow");
});
$
(".MoveLeft").click(function () {
$
(".GalleryItem").animate({
"left": "-=50px"
}, "slow");
$
(".GalleryItem2").animate({
"left": "-=100px"
}, "slow");
});
$
(".Controls").live('click', function () {
if (galleryItemLeft >= "0") {
$
('.MoveRight').hide();
}
else {
$
('.MoveRight').show();
}
});
if (galleryItemWidth == galleryWidth - galleryItemWidth) {
$
('.MoveLeft').hide();
}
});
</script>