I want to add a 'Buy Now' button to Galleria which will trigger adding the im开发者_运维百科age to a visitors cart.
I have the cart code already set up but I am struggling to figure out how to add the custom button to Galleria.
I am currently using the classic theme and have added the image into the map.png. I can set up the CSS no problem but can't figure out how to code the extension to Galleria.
Any help greatly appreciated!
You could attach a buy url to the data object and then assign the url to the button on the image event:
HTML
<div>
<img src="one.jpg">
<a href="buyone.html">Buy now</a>
</div>
<div>
<img src="two.jpg">
<a href="buytwo.html">Buy now</a>
</div>
CSS (example, style as you wish)
.galleria-button {
z-index:3;
padding:5px 10px;
background:#000;
color:#fff;
position:absolute;
top:20px;
left:20px;
cursor:pointer;
}
JS
$('#galleria').galleria({
dataConfig: function(img) {
// return a new buylink key that points to the
// next anchor’s href attribute
return { buylink: $(img).next().attr('href') };
},
extend: function() {
// the current buy link
var buy;
// create the button and append it
this.addElement('button').appendChild('container','button');
// Add text & click event using jQuery
this.$('button').text('Buy now').click(function() {
window.location = buy;
});
// change the buy link on image
this.bind('image', function(e) {
buy = this.getData(e.index).buylink;
});
}
});
you should consider building your own theme. Galleria is 'extensively extendable', and you can add your cart button in the init
function of your theme
精彩评论