【发布时间】:2011-05-25 12:50:27
【问题描述】:
我想向 Galleria 添加一个“立即购买”按钮,这会触发将图片添加到访客购物车。
我已经设置了购物车代码,但我正在努力弄清楚如何将自定义按钮添加到 Galleria。
我目前使用的是经典主题,并已将图像添加到 map.png。我可以设置 CSS 没问题,但不知道如何编写 Galleria 的扩展代码。
非常感谢任何帮助!
【问题讨论】:
标签: javascript jquery galleria
我想向 Galleria 添加一个“立即购买”按钮,这会触发将图片添加到访客购物车。
我已经设置了购物车代码,但我正在努力弄清楚如何将自定义按钮添加到 Galleria。
我目前使用的是经典主题,并已将图像添加到 map.png。我可以设置 CSS 没问题,但不知道如何编写 Galleria 的扩展代码。
非常感谢任何帮助!
【问题讨论】:
标签: javascript jquery galleria
您可以将购买网址附加到数据对象,然后将网址分配给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(例如,你想要的样式)
.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;
});
}
});
【讨论】:
您应该考虑构建your own theme。 Galleria 是“可扩展的”,您可以在主题的init 功能中添加购物车按钮
【讨论】: