I have a products page listing several different products. When a products main image is clicked i would like a popup/lightbox to display with another image of that product and additional information.
However, the click event is only working for the first product. Here's my coffeescript:
This at least gets all the products clickable, but when you click them it still only brings up the the image of the first product. Does that have something to do with the multiple dom elements with the id of #product_popup?
I got it! I needed to remove the position fixed on each image. Thanks so much. I really appreciate you taking the time to make the codepen. You've taught me a lot.
I have a products page listing several different products. When a products main image is clicked i would like a popup/lightbox to display with another image of that product and additional information.
However, the click event is only working for the first product. Here's my coffeescript:
And my html/erb:
Thank you very much!
One solution would be to iterate through each product, and create a button based on the product id.
Your code assigns a constant to the i variable
This code will only create one button.
One way of iterating through each product would be to get all the .main-image class objects, then use the .each() function
It also looks like you will have multiple dom elements with the id of #product_popup
I made a codepen based on the code you posted. It should be helpful, please ask questions.
http://codepen.io/jessecfisher/pen/DdiHn
Thank you for your help! How about this for the coffeescript:
This at least gets all the products clickable, but when you click them it still only brings up the the image of the first product. Does that have something to do with the multiple dom elements with the id of #product_popup?
Ok, so I implemented your coffeescript:
And the html/erb:
But its still only opening the popup for the first product. When you click the others nothing happens. I'm sure I'm just missing something. Thank you!
I got it! I needed to remove the position fixed on each image. Thanks so much. I really appreciate you taking the time to make the codepen. You've taught me a lot.