jquery - 将 Woocommerce 添加到购物车按钮移动到缩略图顶部

标签 jquery css wordpress

关于如何将添加到购物车按钮移动到缩略图顶部的任何想法?

我试过使用钩子(Hook)等,但似乎无法让它位于底部缩略图的顶部,有什么想法吗?

您可以在此页面上看到添加到购物车按钮:https://demo.woothemes.com/storefront/

我想移动按钮,使其看起来像这样:

Example

谢谢,

斯科特

最佳答案

尝试将此添加到您的 CSS:

a.button.product_type_variable.add_to_cart_button{
  position:relative;
  top:-11em;
}

您可以调整 top 值...但是 11em 看起来像您想要的位置。


编辑

你是对的!我没有教过它。
所以它必须用 jQuery 和一些计算来完成。

$("a.button.product_type_variable.add_to_cart_button").each(function(){
  var imageAbove = $(this).closest("li").find("img");
  var imageAbovePos = imageAbove.offset().top;
  var imageAboveHeight = imageAbove.height();

  var thisPos = $(this).offset().top;
  var thisHeight = $(this).height();

  // Position of the bottom of the image
  var imageAboveBottom = imageAbovePos + imageAboveHeight ;

  // This is an arbitrary distance (in pixel) you can play with.
  // It's the distance you wish to have between the bottom of the button and the bottom of the image.
  // It may need more than 20 pixels.
  var distanceFromImageBottom = 20;

  // This is the new position to give to the button.
  var newButtonPos = thisPos - imageAboveBottom - thisHeight - distanceFromImageBottom;

  $(this).css({"position":"relative","top":newButtonPos});
});

关于jquery - 将 Woocommerce 添加到购物车按钮移动到缩略图顶部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45517839/

相关文章:

php - 使用 foreach 从 MySQL 中检索数据

jquery - 如何在semantic-ui下拉选择中实现选项组

javascript - 用于显示异步请求状态的 GUI 组件

html - 带箭头格式的 Div/Li(面包屑)

html - <a> 在 header : only part of it works? 中

html - 如何在 WordPress 中隐藏用户仪表板详细信息?

javascript - CSS3 转换不起作用

javascript - Django Inlineformset - 基于第二个下拉菜单的 JQuery 下拉菜单

HTML 表格如何在悬停时突出显示第一列以外的行?

css - (S)CSS定义全局颜色