Having a bit of a challenge here. I'm attempting to craft my own slider using jQuery along with some css and javascript.
I've managed to get my slider functioning, moving a Div 660px to the left and right upon button clicks.
However, I'm hoping to disable the right button when the left margin reaches 0. Additionally, I'd like the entire div to reset back to 0px after a certain number of clicks.
Is this achievable?
Below is the code I'm currently using:
<script language="javascript">
function example_animate(px) {
$('#slide').animate({
'marginLeft' : px
});
}
</script>
<div class="container">
<div class="row">
<div class="contr-left">
<a type="button" value="Move Left" onclick="example_animate('-=600px')"><i class="fa fa-chevron-circle-left fa-2x" aria-hidden="true" ></i></a>
</div>
<div id="carreview" class="carousel" data-ride="carousel" style="opacity: 1; display: block;">
<div class="wrapper-outer">
<div class="wrapper-inner" id="slide">
<?php get_template_part('loop-reviews');?>
</div>
</div>
<div class="contr-right">
<a type="button" value="Move Right" onclick="example_animate('+=600px')"><i class="fa fa-chevron-circle-right fa-2x" aria-hidden="true" ></i></a>
</div>
</div>
</div>
</div>
The code I'm utilizing can be found on this page: Page
After applying the code from Rayn, the button now hides, but unfortunately, it doesn't reappear when the left-margin is set to 1px. Hence, I am now attempting the following solution: (although it does not work)
Trying this now: (does not work though) `function example_animate(px) {
$('#slide').animate({
'marginLeft' : px
});
var slidemarginleft = $('#slide').css('margin-left'); //this gets the value of margin-left
if(slidemarginleft == '0px'){
$('.contr-right').hide();
} else (slidemarginleft == '1px') {
$('.contr-right').show();
}
}`
Additionally, I've noticed that the margin-left property isn't defined in the style sheet but within the
<div style="margin-left:0px">content</div>