- This topic is empty.
Viewing 1 post (of 1 total)
Viewing 1 post (of 1 total)
- The forum ‘JavaScript’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
Home › Forums › JavaScript › How to multiply gallery
Hi guys!
I have this piece of code someone passed me:
jQuery(document).ready(function(){
// Gallery
if(jQuery(".prod-gallery1").length){
// Declare variables
var totalImages1 = jQuery(".prod-gallery1 > li").length,
currentImage1 = 1,
imageWidth = jQuery(".prod-gallery1 > li:first").outerWidth(true),
totalWidth1 = imageWidth * totalImages1,
visibleImages1 = Math.round(jQuery(".prod-gallery-visible-area1").width() / imageWidth),
visibleWidth1 = visibleImages1 * imageWidth,
stopPosition = (visibleWidth1 - totalWidth1);
jQuery(".prod-gallery1").width(totalWidth1);
jQuery(".prod-gallery-prev1").click(function(){
if(currentImage1 != 1 && !jQuery(".prod-gallery1").is(":animated")){
jQuery(".prod-gallery1").animate({left : "+=" + imageWidth + "px"});
currentImage1--;
}
return false;
});
jQuery(".prod-gallery-next1").click(function(){
if(currentImage1 < totalImages1 && !jQuery(".prod-gallery1").is(":animated")){
jQuery(".prod-gallery1").animate({left : "-=" + imageWidth + "px"});
currentImage1++;
}
return false;
});
}
});
So i want to replicate the code but i don’t want to write it multiple times, and since i don’t know jquery very well (or even javascript) i don’t know if i can make some function that gets the elements and act on them. Something like:
function gallery($prod-gallery, $prod-next, $prod-prev, $prod-area)
I don’t need to get the code from you guys, just some guidelines. Thank you in advance.