图片/图形

商品购物添加购物车界面设计

阿里云


这是一款简单实用的商品购物和添加购物车界面设计方案。用户可以在商品购物界面中预览各种型号、颜色、尺寸的商品。然后通过点击添加到购物车按钮就可以将该商品添加到购物车中,操作简单直观。在传统的购物网站中,用户在商品展示界面看中了一件商品之后,点击这件商品的缩略图,然后可以键入到对应水平的子页面中。在这个子页面中,用户可以选择查看一些商品的属性,然后把商品添加到购物车中。但是在这个购物车界面设计中,用户可以直接在购物界面查看商品的属性,并直接将商品添加到购物车中,简化了用户的操作,大大提升了用户的体验度。通过在商品预览图界面添加“快速添加到购物车”按钮,可以减少用户的操作步骤,提升用户体验,增加转化率。

HTML 结构

该购物界面的 HTML 结构使用一个无序列表来制作。每一个无序列表项中又包含一个无序列表,由于制作商品的图片画廊。div.cd-customization 是包含商品的属性和“添加到购物车”按钮的面板。div.cd-item-info 是商品的名称和价格。

也想出现在这里?联系我们
创客主机
  1. <ul class="cd-gallery">
  2.   <li>
  3.     <div class="cd-single-item">
  4.       <a href="#0">
  5.         <ul class="cd-slider-wrapper">
  6.           <li class="selected"><img src="img/thumb-1.jpg" alt="Preview image"></li>
  7.           <li><img src="img/thumb-2.jpg" alt="Preview image"></li>
  8.           <!-- other product images here -->
  9.         </ul>
  10.       </a>
  11.  
  12.       <div class="cd-customization">
  13.         <div class="color" data-type="select">
  14.           <ul>
  15.             <li class="color-1 active">color-1</li>
  16.             <li class="color-2">color-2</li>
  17.             <!-- other product colors here -->
  18.           </ul>
  19.         </div>
  20.  
  21.         <div class="size" data-type="select">
  22.           <ul>
  23.             <li class="small active">Small</li>
  24.             <li class="medium">Medium</li>
  25.             <!-- other product sizes here -->
  26.           </ul>
  27.         </div>
  28.  
  29.         <button class="add-to-cart">
  30.           <em>Add to Cart</em>
  31.           <svg x="0px" y="0px" width="32px" height="32px" viewBox="0 0 32 32">
  32.             <path stroke-dasharray="19.79 19.79" stroke-dashoffset="19.79" fill="none" stroke="#FFFFFF" stroke-width="2" stroke-linecap="square" stroke-miterlimit="10" d="M9,17l3.9,3.9c0.1,0.1,0.2,0.1,0.3,0L23,11"/>
  33.           </svg>
  34.         </button>
  35.       </div> <!-- .cd-customization -->
  36.  
  37.       <button class="cd-customization-trigger">Customize</button>
  38.     </div> <!-- .cd-single-item -->
  39.  
  40.     <div class="cd-item-info">
  41.       <b><a href="#0">Product Name</a></b>
  42.       <em>$9.99</em>
  43.     </div> <!-- cd-item-info -->
  44.   </li>
  45.  
  46.   <!-- other list items here -->
  47. </ul> <!-- cd-gallery -->

CSS 样式

对于商品的图片画廊,默认情况下,列表项使用绝对定位,并被移动到它的父元素.cd-gallery 之外,因此它们是不可见的。它们使用了两个 class:.selected 用于添加到列表项的第一项,使其可见,.move-left,图片向左移动,使其不可见。

  1. .cd-slider-wrapper {
  2.   position: relative;
  3.   overflow: hidden;
  4. }
  5. .cd-slider-wrapper li {
  6.   position: absolute;
  7.   top: 0;
  8.   left: 0;
  9.   visibility: hidden;
  10.   /* by default, move the product image to the right*/
  11.   transform: translateX(100%);
  12.   transition: transform 0.3s 0s, visibility 0s 0.3s;
  13. }
  14. .cd-slider-wrapper li.selected {
  15.   /* this is the visible product image */
  16.   position: relative;
  17.   visibility: visible;
  18.   z-index: 1;
  19.   transform: translateX(0);
  20.   transition: transform 0.3s 0s, visibility 0s 0s;
  21. }
  22. .cd-slider-wrapper li.move-left {
  23.   /* move the product image to the left */
  24.   transform: translateX(-100%);
  25. }

.cd-customization 元素在用户用鼠标滑过商品缩略图时才被显示出来。它使用绝对定位并放置在父元素.cd-single-item 的下面。为了创建自定义选项(商品的颜色和尺寸),这里使用了不同的<ul>元素,它们都被包裹在 div[data-type="select"]元素中。<ul>元素使用绝对定位,并相对于他们的父元素居中。它们的父元素 div[data-type="select"]有固定的高度(34px)以及 overflow:hidden 属性。无序列表中的每一个列表项的高度都和 div[data-type="select"]相同,因此默认情况下,只有被选择的项是可见的。当用户点击了某个自定义选项时,div[data-type="select"]的 overflow 属性被设置为可见,这样整个<ul>元素都被显示出来。

  1. .cd-customization {
  2.   position: absolute;
  3.   left: 0;
  4.   bottom: 0;
  5.   width: 100%;
  6.   visibility: hidden;
  7.   opacity: 0;
  8. }
  9.  
  10. .no-touch .cd-single-item:hover .cd-customization {
  11.   /* product customization visible */
  12.   pointer-events: auto;
  13.   visibility: visible;
  14.   opacity: 1;
  15. }
  16.  
  17. .cd-customization .color, .cd-customization .size {
  18.   height: 34px;
  19.   position: relative;
  20.   overflow: hidden;
  21. }
  22. .cd-customization .color ul, .cd-customization .size ul {
  23.   display: inline-block;
  24.   position: absolute;
  25.   left: 50%;
  26.   top: 50%;
  27.   transform: translateX(-50%) translateY(-50%);
  28.   width: 100%;
  29. }
  30. .cd-customization .color.is-open, .cd-customization .size.is-open {
  31.   /* color/size list open - make ul element visible */
  32.   overflow: visible;
  33. }

为了确保被选择的<li>元素一直可见,插件中通过创建.selected-n class 对<ul>元素中的列表项进行了重新排列。例如:当第 3 个列表项被选择的时候,.selected-3 会被添加到 div[data-type="select"]中。

  1. .cd-customization .color.selected-3 ul li:first-of-type, 
  2. .cd-customization .size.selected-3 ul li:first-of-type {
  3.   /* third option selected in the ul.color/ul.size list */
  4.   transform: translateY(0);
  5. }
  6. .cd-customization .color.selected-3 ul li:nth-of-type(2), 
  7. .cd-customization .size.selected-3 ul li:nth-of-type(2) {
  8.   transform: translateY(100%);
  9. }
  10. .cd-customization .color.selected-3 ul li:nth-of-type(3), 
  11. .cd-customization .size.selected-3 ul li:nth-of-type(3) {
  12.   transform: translateY(-100%);
  13. }

“添加到购物车”按钮.add-to-cart 由一个<em>元素(按钮上的文本)和一个 SVG(check 图标)组成。默认情况下,图标是不可见的。当商品被添加到购物车的时候,.add-to-cart 按钮被添加了.is-added class:此时<em>元素被隐藏(移动到左边),SVG 图标被移动回中间,然后开始绘制动画。

  1. .cd-customization .add-to-cart em {
  2.   /* this is the button text message */
  3.   position: absolute;
  4.   top: 0;
  5.   left: 0;
  6.   width: 100%;
  7.   height: 100%;
  8. }
  9. .cd-customization .add-to-cart svg {
  10.   /* this is the check icon */
  11.   position: absolute;
  12.   left: 50%;
  13.   top: 50%;
  14.   width: 100%;
  15.   /* move the icon on the right - outside the button */
  16.   transform: translateX(50%) translateY(-50%);
  17. }
  18. .cd-customization .add-to-cart.is-added em {
  19.   /* product added to the cart - hide text message on the left with no transition*/
  20.   color: transparent;
  21.   transform: translateX(-100%);
  22. }
  23. .cd-customization .add-to-cart.is-added svg {
  24.   /* product added to the cart - move the svg back inside the button */
  25.   transform: translateX(-50%) translateY(-50%);
  26. }

SVG 图标的绘制动画使用的是 stroke-dasharray 和 stroke-dashoffset 属性。如果你对 SVG 感兴趣,可以点击这里查看关于 SVG 教程。

  1. <svg x="0px" y="0px" width="32px" height="32px" viewBox="0 0 32 32">
  2.   <path stroke-dasharray="19.79 19.79" stroke-dashoffset="19.79" fill="none" stroke="#FFFFFF" stroke-width="2" stroke-linecap="square" stroke-miterlimit="10" d="M9,17l3.9,3.9c0.1,0.1,0.2,0.1,0.3,0L23,11"/>
  3. </svg>

javascript 代码请参考下载文件。

商品购物添加购物车界面设计

已有 603 人购买
查看演示升级 VIP立刻购买

演示地址 下载地址
收藏
(0)

发表回复

热销模板

Ashade - 作品展示摄影相册WordPress汉化主题
LensNews

本站承接 WordPress / PbootCMS / DedeCMS 等
系统建站、仿站、开发、定制等业务!