【问题标题】:Overlapping images with hover effects具有悬停效果的重叠图像
【发布时间】:2016-04-13 07:05:26
【问题描述】:

我正在尝试实现一种效果,其中 3 个向上箭头图形相互挤压,当您将鼠标悬停在一个上时,箭头会变大,单击时您会被带到一个新页面。

我遇到的问题是当箭头重叠时,图像的透明部分会响应悬停。

构建它的最佳方法是什么?我在考虑svg,但图形太复杂了。

这些箭头中的每一个都是一个单独的图像,并且在悬停时它们会放大。但重叠部分在图形之间移动时会导致意外行为。

这是我目前所拥有的链接。 http://show.issa.com.php56-33.ord1-1.websitetestlink.com/

【问题讨论】:

  • 请将所有相关代码贴在原帖中,不要只给出链接。谢谢!
  • 您可以覆盖一些 div 来激活功能,这会非常不准确和混乱,但可能会起作用。顺便说一句,您的网站看起来很棒
  • 顺其自然,试试 SVG 选项。您可能会对最终结果感到惊讶。我不会说这些图形都那么复杂。

标签: javascript html css svg css-shapes


【解决方案1】:

您可以“伪造”它并创建三个透明区域 - 如果您需要精确的箭头形状,甚至可以使用 SVG - 最重要的是并将它们用于交互。这很容易通过纯 javascript 或 Jquery 实现。

【讨论】:

    【解决方案2】:

    我正在查看这个并手动添加了内联 borderoutline,我可以看到颜色非常浅的 dotted 边框,虽然它看起来像一个子元素。

    我没有看到任何影子 DOM。

    我没有看到任何其他子元素。

    确实看到了什么会在 Firefox、Chrome 和 IE11 中有效地被视为 border-right

    我确实看到了一些很长的疯狂 CSS,应该替换为:

    `* {}`
    

    虚线边框是图像的部分!您需要加载图像并非常接近地放大,但它就在那里!

    【讨论】:

      【解决方案3】:

      我想通了。万一有人想知道,我可以将 SVG 与内联图像一起使用。在图像的顶部,我添加了一个多边形,其点与箭头的粗略轮廓相匹配。该多边形添加了一个 svg 链接,除了多边形之外的所有内容都有pointer-event: none;

      对于任何想要代码的人:

      function addPrevClass(e) {
        var target = e.target;
        if (target.getAttribute('points')) { // check if it is svg
          var li = target.parentNode.parentNode.parentNode;
          var prevLi = li.previousElementSibling;
          if (prevLi) {
            prevLi.className = 'prev';
          }
          if (li) {
            li.className = 'current-hover';
          }
      
          target.addEventListener('mouseout', function() {
            if (prevLi) {
              prevLi.removeAttribute('class');
            }
            if (li) {
              li.removeAttribute('class');
            }
          }, false);
        }
      }
      if (window.addEventListener) {
        document.getElementById("unleashed").addEventListener('mouseover', addPrevClass, false);
      }
      #unleashed-container {
        position: absolute;
        text-align: center;
        left: 0;
        right: 0;
        bottom: 80px;
        margin: auto;
        height: 100%;
        z-index: -99;
      }
      #unleashed-container #unleashed {
        height: 100%;
      }
      #unleashed-container #unleashed ul {
        height: 100%;
        overflow: hidden;
      }
      #unleashed-container #unleashed ul li {
        list-style-type: none;
        display: inline-block;
        text-align: center;
        margin: 0;
        height: 100%;
        position: relative;
        width: 14%;
        pointer-events: none;
      }
      #unleashed-container #unleashed ul li#pink-arrow {
        margin-left: -7.28%;
        margin-right: -7.3346%;
        width: 18.2%;
        z-index: 1;
      }
      #unleashed-container #unleashed ul li#blue-arrow {
        z-index: 2;
      }
      #unleashed-container #unleashed ul li#green-arrow {
        z-index: 0;
      }
      #unleashed-container #unleashed ul li a {
        display: block;
        height: 100%;
        position: relative;
      }
      #unleashed-container #unleashed ul li a img {
        -moz-transition: 0.3s;
        -o-transition: 0.3s;
        -webkit-transition: 0.3s;
        transition: 0.3s;
        -moz-transform-origin: 50% 100%;
        -ms-transform-origin: 50% 100%;
        -webkit-transform-origin: 50% 100%;
        transform-origin: 50% 100%;
        width: 100%;
        position: absolute;
        bottom: 0;
        right: 0;
      }
      #unleashed-container #unleashed ul li svg {
        display: block;
        -moz-transition: 0.3s;
        -o-transition: 0.3s;
        -webkit-transition: 0.3s;
        transition: 0.3s;
        -moz-transform-origin: 50% 100%;
        -ms-transform-origin: 50% 100%;
        -webkit-transform-origin: 50% 100%;
        transform-origin: 50% 100%;
        width: 100%;
        position: absolute;
        bottom: 0;
        right: 0;
        pointer-events: none;
      }
      #unleashed-container #unleashed ul li svg image {
        pointer-events: none;
      }
      #unleashed-container #unleashed ul li svg polygon {
        pointer-events: fill;
      }
      #unleashed-container #unleashed ul li.current-hover .tooltip {
        display: none;
      }
      #unleashed-container #unleashed ul li.current-hover img,
      #unleashed-container #unleashed ul li.current-hover svg {
        -moz-transform: scale(1.2, 1.2);
        -ms-transform: scale(1.2, 1.2);
        -webkit-transform: scale(1.2, 1.2);
        transform: scale(1.2, 1.2);
      }
      #unleashed-container #unleashed ul li:hover + li img,
      #unleashed-container #unleashed ul li.prev img,
      #unleashed-container #unleashed ul li:hover + li svg,
      #unleashed-container #unleashed ul li.prev svg {
        -moz-transform: scale(1.05, 1.05);
        -ms-transform: scale(1.05, 1.05);
        -webkit-transform: scale(1.05, 1.05);
        transform: scale(1.05, 1.05);
      }
      <div id="unleashed-container">
        <div id="unleashed">
          <ul>
            <li id="blue-arrow">
              <svg class="arrow" id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 875.67 1418">
                <image width="850" height="1412" xlink:href="http://show.issa.com.php56-33.ord1-1.websitetestlink.com/wp-content/themes/issa2016/images/blue-arrow.png"></image>
                <a xlink:href="http://show.issa.com.php56-33.ord1-1.websitetestlink.com/attend/">
                  <polygon points="0.5 550.19 0.5 575.71 170.5 575.71 173.96 1417.5 705.17 1417.5 705.17 584.78 875.17 584.78 875.17 559.27 453.17 0.5 423.17 0.5 0.5 550.19" opacity="0" style="fill: #333"></polygon>
                </a>
              </svg>
            </li>
            <li id="pink-arrow">
              <svg class="arrow" id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 850 1648">
                <image width="850" height="1648" xlink:href="http://show.issa.com.php56-33.ord1-1.websitetestlink.com/wp-content/themes/issa2016/images/pink-arrow.png"></image>
                <a xlink:href="http://show.issa.com.php56-33.ord1-1.websitetestlink.com/attend/">
                  <polygon points="425 0 0 554.78 172.79 554.78 172.79 1648 673.84 1648 673.84 560.78 850 560.78 425 0" opacity="0" style="fill: #333"></polygon>
                </a>
              </svg>
            </li>
            <li id="green-arrow">
              <svg class="arrow" id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 875.67 1418">
                <image width="850" height="1412" xlink:href="http://show.issa.com.php56-33.ord1-1.websitetestlink.com/wp-content/themes/issa2016/images/green-arrow.png"></image>
                <a xlink:href="http://show.issa.com.php56-33.ord1-1.websitetestlink.com/attend/">
                  <polygon points="0.5 550.19 0.5 575.71 170.5 575.71 173.96 1417.5 705.17 1417.5 705.17 584.78 875.17 584.78 875.17 559.27 453.17 0.5 423.17 0.5 0.5 550.19" opacity="0" style="fill: #333"></polygon>
                </a>
              </svg>
            </li>
          </ul>
        </div>
      </div>

      【讨论】:

        猜你喜欢
        • 2021-06-23
        • 1970-01-01
        • 2017-07-04
        • 2020-01-23
        • 1970-01-01
        • 2014-05-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多