Forked from drabbytux/make-image-change-javascript.js
Last active
May 31, 2022 13:47
-
-
Save jonathanmoore/13a5bdb0552e18baded878b7d8fd28f2 to your computer and use it in GitHub Desktop.
Make Image Change javascript (for theme.js file)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function() { | |
thumbnails = $('img[src*="/products/"]').not(':first'); | |
if (thumbnails.length) { | |
thumbnails.bind('click', function() { | |
var arrImage = $(this).attr('src').split('?')[0].split('.'); | |
var strExtention = arrImage.pop(); | |
var strRemaining = arrImage.pop().replace(/_[a-zA-Z0-9@]+$/,''); | |
var strNewImage = arrImage.join('.')+"."+strRemaining+"."+strExtention; | |
if (typeof variantImages[strNewImage] !== 'undefined') { | |
productOptions.forEach(function (value, i) { | |
optionValue = variantImages[strNewImage]['option-'+i]; | |
if (optionValue !== null && $('.single-option-selector:eq('+i+') option').filter(function() { return $(this).text().trim() === optionValue }).length) { | |
$('.single-option-selector:eq('+i+')').val(optionValue).trigger('change'); | |
} | |
}); | |
} | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ok i found a solution after few hours searching :)
Here the code in product file :
`
And here the javascript :
` <script>
</script> `var selectCallback = function(variant, selector) {