Skip to content

Instantly share code, notes, and snippets.

@Carolusian
Created July 18, 2014 08:15
Show Gist options
  • Save Carolusian/82e293f334701e34b962 to your computer and use it in GitHub Desktop.
Save Carolusian/82e293f334701e34b962 to your computer and use it in GitHub Desktop.
EShop slide for products: A slide show which, while display the current image, can show a edge of the next image. So users knows there are more images to be checked
$.fn.productSlide = (options) ->
settings =
width: 250
container: "slide-container"
# space left to display part of another photo
edge: 30
imageWidth: 190
settings = $.extend settings, options
#Put arbitary images in one row
($ "#"+settings.container).css "width", "10000000px"
($ "#"+settings.container).css "margin-left", settings.edge + "px"
($ "#"+settings.container+" img").each ->
($ this).css "width", settings.imageWidth
n = 0
numOfImages = ($ "#"+settings.container+" img").length
#Move to next picture
@next = ->
n = n+1 if n<numOfImages-1
($ "#" + settings.container).css "margin-left", (settings.edge - settings.imageWidth * n) + "px"
console.log settings.edge+','+settings.imageWidth*n
@prev = ->
n = n-1 if n > 0
($ "#" + settings.container).css "margin-left", (settings.edge - settings.imageWidth * n) + "px"
console.log settings.edge+','+settings.imageWidth*n
@each ->
#set the width of the slide
($ this).css "width", settings.width + "px"
($ this).css "overflow", "hidden"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment