【问题标题】:The animation does not work when I hover around the border当我将鼠标悬停在边框周围时,动画不起作用
【发布时间】:2019-08-02 16:58:37
【问题描述】:

当我将鼠标悬停在边框上时,动画不呈现

原码笔链接如下图 https://codepen.io/anon/pen/GVvxqq

我需要保留产品类 css

如何在不影响产品类的情况下添加动画?

    //HTML

    <template>
      <div class="item button draw">
        <b-link @click="productDetail(item.productId)">
          <div class="product">

              <a class="img-prod">
                <img
                  class="img-fluid product-image"
                  :src="item.options[0].productImages[0].imageUrl"
                  alt="Product Item"
                />
                <span v-if="item.discounts.length != 0" class="status">{{discountPercentageTag}}% OFF</span>
              </a>

              <div class="text pt-3 px-3">
                <h3>{{item.productName}}</h3>
                <div class="d-flex">
                  <div class="pricing">
                    <p v-if="item.discounts.length != 0" class="price">
                      <span class="mr-2 price-dc">${{item.price.toFixed(2)}}</span>
                      <span class="price-sale">${{discountPrice.toFixed(2)}}</span>
                    </p>
                    <p v-else class="price">
                      <span>${{item.price.toFixed(2)}}</span>
                    </p>
                  </div>
                </div>
              </div>
            </div>


        </b-link>
      </div>
    </template>


    //CSS
    i need the product class css to remain

   .product{
    display: block;
    width: 100%;
    margin-bottom: 30px;
    @include media-breakpoint-down(md){
        margin-bottom: 30px;
    }

    .button {
        background: none;
        border: 0;
        box-sizing: border-box;
        margin: 1em;
        padding: 1em 2em;
        box-shadow: inset 0 0 0 2px #f45e61;
        color: #f45e61;
        font-size: inherit;
        font-weight: 700;
        position: relative;
        vertical-align: middle;
      }
      .button::before, .button::after {
        box-sizing: inherit;
        content: '';
        position: absolute;
        width: 100%;
        height: 100%;
      }
      .draw {
        transition: color 0.25s;
      }
      .draw::before, .draw::after {
        border: 2px solid transparent;
        width: 0;
        height: 0;
      }
      .draw::before {
        top: 0;
        left: 0;
      }
      .draw::after {
        bottom: 0;
        right: 0;
      }
      .draw:hover::before, .draw:hover::after {
        width: 100%;
        height: 100%;
      }
      .draw:hover::before {
        border-top-color: #60daaa;
        border-right-color: #60daaa;
        transition: width 0.25s ease-out, height 0.25s ease-out 0.25s;
      }
      .draw:hover::after {
        border-bottom-color: #60daaa;
        border-left-color: #60daaa;
        transition: border-color 0s ease-out 0.5s, width 0.25s ease-out 0.5s, height 0.25s ease-out 0.75s;
      }



    .img-prod{
        position: relative;
        display: block;
        overflow: hidden;
        span.status{
            position: absolute;
            top: 10px;
            left: -1px;
            padding: 2px 15px;
            color: $black;
            font-weight: 300;
            background: $primary;
        }
        img{
            -webkit-transform: scale(1.0);
            -moz-transform: scale(1.0);
            -ms-transform: scale(1.0);
            -o-transform: scale(1.0);
            transform: scale(1.0);
            @include transition(.3s);
        }
        &:hover, &:focus{
            img{
                -webkit-transform: scale(1.1);
                -moz-transform: scale(1.1);
                -ms-transform: scale(1.1);
                -o-transform: scale(1.1);
                transform: scale(1.1);
            }
        }
    }

    Only the border colour is rendered but not the animation

【问题讨论】:

    标签: html css


    【解决方案1】:

    我已经解决了。 template 标签有问题,我已将其删除并正常工作。

    .button {
      background: none;
      border: 0;
      box-sizing: border-box;
      margin: 1em;
      padding: 1em 2em;
      box-shadow: inset 0 0 0 2px #f45e61;
      color: #f45e61;
      font-size: inherit;
      font-weight: 700;
      position: relative;
      vertical-align: middle;
    }
    img{width:100%}
    .button::before, .button::after {
      box-sizing: inherit;
      content: '';
      position: absolute;
      width: 100%;
      height: 100%;
    }
    .draw {
      transition: color 0.25s;
    }
    .draw::before, .draw::after {
      border: 2px solid transparent;
      width: 0;
      height: 0;
    }
    .draw::before {
      top: 0;
      left: 0;
    }
    .draw::after {
      bottom: 0;
      right: 0;
    }
    .draw:hover::before, .draw:hover::after {
      width: 100%;
      height: 100%;
    }
    .draw:hover::before {
      border-top-color: #60daaa;
      border-right-color: #60daaa;
      transition: width 0.25s ease-out, height 0.25s ease-out 0.25s;
    }
    .draw:hover::after {
      border-bottom-color: #60daaa;
      border-left-color: #60daaa;
      transition: border-color 0s ease-out 0.5s, width 0.25s ease-out 0.5s, height 0.25s ease-out 0.75s;
    }
      <div class="item button draw">
        <b-link @click="productDetail(item.productId)">
          <div class="product">
            <a class="img-prod">
              <img
                class="img-fluid product-image"
                :src="https://colorlib.com/wp/wp-content/uploads/sites/2/store-free-template.jpg"
                alt="Product Item"
              />
              <spanclass="status">test OFF</span>
            </a>
    
            <div class="text pt-3 px-3">
              <h3>test</h3>
              <div class="d-flex">
                <div class="pricing">
                  <p v-if="item.discounts.length != 0" class="price">
                    <span class="mr-2 price-dc">$5423</span>
                    <span class="price-sale">$5345</span>
                  </p>
                  <p v-else class="price">
                    <span>$435345</span>
                  </p>
                </div>
              </div>
            </div>
          </div>
        </b-link>
      </div>

    【讨论】:

    • 您好,它不起作用,只有当我删除我的产品类但我想保留它时它才起作用。感谢广告
    • 我已经在模板标签出现问题的地方更新了答案。
    【解决方案2】:

    如果您想按原样使用 codepen 中的 CSS,则需要将整个块包装在 &lt;section class="buttons"&gt; 中,并将最外面的 &lt;div&gt; 更改为 &lt;button&gt;。我已经对此进行了测试,它可以按预期工作。

    <template>
        <section class="buttons">
            <button class="item button draw">
                <b-link @click="productDetail(item.productId)">
                    //
                    // custom element content
                    //
                </b-link>
            </button>
        </section>
    </template>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-18
      • 1970-01-01
      • 2014-09-22
      • 2013-04-08
      • 2014-08-13
      • 2011-10-29
      相关资源
      最近更新 更多