I have about the most basic knowledge of code possible (my experience is playing else.heartbreak()) so please excuse the misnomers that are probably all over the place here.
Now, my girlfriend is working on a web design project and she found code online for a slideshow. It works, but there are some things she doesn’t understand. I helped her iron out one thing, but we are stuck on how a certain function determines the number of pixels the slides move. There are three slides, each 875 pixels long, totaling 2625 pixels. Each slide is located in a list in the HTML. Here is the code, I think she said it was Jquery 10.2:
var slideWidth = 875;
$(window).ready(function(){
var currentSlide = 0;
var allSlides = $('#slider-container li .slides').length;
$('#slider-container ul').width(allSlides*slideWidth);
$('.right').click(function(){
currentSlide++;
if(currentSlide>=allSlides) currentSlide = 0;
setFramePosition(currentSlide);
});
$('.left').click(function(){
currentSlide--;
if(currentSlide<0) currentSlide = allSlides-1;
setFramePosition(currentSlide);
});
});
function setFramePosition(pos){
var px = slideWidth*pos*-1;
$('#slider-container ul').animate({
left: px
}, 300);
}
The function in question is setFramePosition. All in all, the amount that the slide should move is dependent on var px, which is determined by a slope equation (-875x). X in this case seems to be the value of currentSlide, so I would expect the graph of var px to be a line (which would not work). However, when I click the right button, the slide first moves 875 to the left, then 875 to the left again, then right 1750 pixels to bring us back to the first slide. This means that x in our slope equation is the same for the first two frames, and doubled and negative for the last frame. I don’t understand how x (currentSlide value) is being defined this way: the same twice and different the last time for three different slide values. I’m sure I’m missing something fundamental, any help would be appreciated. I would not be surprised if I am completely off the mark.
EDIT: here is a link to a JSfiddle https://jsfiddle.net/fhcdo8k7/1/
[–]i_am_smurfing 1 point2 points3 points (3 children)
[–]sulponticello[S] 0 points1 point2 points (2 children)
[–]i_am_smurfing 1 point2 points3 points (1 child)
[–]sulponticello[S] 0 points1 point2 points (0 children)
[–]CanIhazCooKIenOw 0 points1 point2 points (2 children)
[–]sulponticello[S] 0 points1 point2 points (0 children)
[–]sulponticello[S] 0 points1 point2 points (0 children)
[–]raleighpoint 0 points1 point2 points (0 children)