I have been working for some time on a javascript function that makes the next div when I click on the background image, or for time.
Well this function and I got it, the problem is that now I can not do that by clicking on the right side go to the next and if I click on the left side move back.
This is the function I have for now:
<script type='text/javascript'>//<![CDATA[
$(document).ready(function() {
var boxContainer = $('.boxes');
var allBoxes = boxContainer.children("div");
var timeout;
transitionBox(null, allBoxes.first());
boxContainer.click(function() {
var from = boxContainer.children('div:visible');
var to = findNext(from);
transitionBox(from, to);
});
function findNext(to) {
if (to.is(":last-child")) {
return to.closest(".boxes").children("div").first();
} else {
return to.next();
}
}
function transitionBox(from, to) {
clearTimeout(timeout);
function next() {
var nextTo = findNext(to);
to.fadeIn(500, function() {
timeout = setTimeout(function() {
transitionBox(to, nextTo);
}, 5000);
});
}
if (from) {
from.fadeOut(800, next);
} else {
next();
}
}
});
</script>
They recommended me to make a few floating buttons of direction like a standard slider to control it with an event.stopPropagation (), but I do not do it.
Thank you very much in advance.
I leave you here the jsFiddle: link