javascript - 无需将鼠标悬停在 WordPress 中的 Image Accordion Gallery 上即可显示标题

标签 javascript jquery css wordpress jquery-ui-accordion

这是我的网站。

https://developer.blink-eye.com/prifer/index.php/en/index/

如果您向下滚动到“我们的宗旨”部分,您会找到一个画廊。

我的问题是我在我的网站上使用了 Image Accordion 插件。默认情况下,它显示标题和解密,但悬停在每个垂直部分上。 我希望它只显示没有悬停的标题,而悬停在标题和描述上就像它现在显示的那样。

我尝试通过针对不同的类使用外部 CSS 来实现此目的,但没有出现标题。在某些时候,如果它们出现,则它们没有对齐。

我想这是我们可以用 JavaScript 做的事情,但我不是专家,无法编写更多代码,因为我现在已经厌倦了。

现在寻求专家的帮助。

提前致谢。

JS

var ImageAccordion = function($scope, $) {
    var $imageAccordion = $scope.find(".eael-img-accordion").eq(0),
        $id =
            $imageAccordion.data("img-accordion-id") !== undefined
                ? $imageAccordion.data("img-accordion-id")
                : "",
        $type =
            $imageAccordion.data("img-accordion-type") !== undefined
                ? $imageAccordion.data("img-accordion-type")
                : "";

    if ("on-click" === $type) {
        $("#eael-img-accordion-" + $id + " a").on("click", function(e) {
            if ($(this).hasClass("overlay-active") == false) {
                e.preventDefault();
            }

            $("#eael-img-accordion-" + $id + " a").css("flex", "1");
            $(this)
                .find(".overlay")
                .parent("a")
                .addClass("overlay-active");
            $("#eael-img-accordion-" + $id + " a")
                .find(".overlay-inner")
                .removeClass("overlay-inner-show");
            $(this)
                .find(".overlay-inner")
                .addClass("overlay-inner-show");
            $(this).css("flex", "3");
        });
        $("#eael-img-accordion-" + $id + " a").on("blur", function(e) {
            $("#eael-img-accordion-" + $id + " a").css("flex", "1");
            $("#eael-img-accordion-" + $id + " a")
                .find(".overlay-inner")
                .removeClass("overlay-inner-show");
            $(this)
                .find(".overlay")
                .parent("a")
                .removeClass("overlay-active");
        });
    }
};
jQuery(window).on("elementor/frontend/init", function() {
    elementorFrontend.hooks.addAction(
        "frontend/element_ready/eael-image-accordion.default",
        ImageAccordion
    );
});

CSS

/*------------------------------*/
/* 34. Image accordion
/*------------------------------*/
.eael-img-accordion {
  display: -webkit-box;
  display: -webkit-flex;
  display: -ms-flexbox;
  display: flex;
  height: 50vh;
}

.eael-img-accordion a {
  position: relative;
  -webkit-box-flex: 1;
  -webkit-flex: 1;
      -ms-flex: 1;
          flex: 1;
  text-align: center;
  text-decoration: none;
  color: #fff;
  -webkit-background-size: cover;
          background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  -webkit-transition: -webkit-box-flex .4s, -webkit-flex .4s;
  transition: -webkit-box-flex .4s, -webkit-flex .4s;
  -o-transition: flex .4s;
  transition: flex .4s;
  transition: flex .4s, -webkit-box-flex .4s, -webkit-flex .4s, -ms-flex .4s;
}

.eael-grow-accordion {
  -webkit-box-flex: 3;
  -webkit-flex: 3;
      -ms-flex: 3;
          flex: 3;
}

.eael-img-accordion .overlay {
  display: -webkit-box;
  display: -webkit-flex;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-align: center;
  -webkit-align-items: center;
      -ms-flex-align: center;
          align-items: center;
  -webkit-box-pack: center;
  -webkit-justify-content: center;
      -ms-flex-pack: center;
          justify-content: center;
  padding: 0 10px;
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  -webkit-transition: background-color .4s;
  -o-transition: background-color .4s;
  transition: background-color .4s;
}

.eael-img-accordion .overlay .overlay-inner {
  z-index: 1;
}

.eael-img-accordion a:after {
  content: "";
  position: absolute;
  width: 100%;
  height: 100%;
  z-index: 0;
  top: 0px;
  left: 0px;
  bottom: 0px;
  right: 0px;
  -webkit-transition: all 0.3s ease-in-out;
  -o-transition: all 0.3s ease-in-out;
  transition: all 0.3s ease-in-out;
}

.eael-img-accordion .overlay-inner * {
  visibility: hidden;
  opacity: 0;
  -webkit-transform-style: preserve-3d;
          transform-style: preserve-3d;
}

.eael-img-accordion .overlay h2 {
  color: #fff;
  -webkit-transform: translate3d(0, -60px, 0);
          transform: translate3d(0, -60px, 0);
}

.eael-img-accordion .overlay p {
  color: #fff;
  -webkit-transform: translate3d(0, 60px, 0);
          transform: translate3d(0, 60px, 0);
}

.eael-img-accordion .overlay-inner-show * {
  opacity: 1;
  visibility: visible;
  -webkit-transform: none !important;
      -ms-transform: none !important;
          transform: none !important;
  -webkit-transition: all .3s .3s;
  -o-transition: all .3s .3s;
  transition: all .3s .3s;
}

@media screen and (max-width: 800px) {
  .eael-img-accordion {
    -webkit-box-orient: vertical;
    -webkit-box-direction: normal;
    -webkit-flex-direction: column;
        -ms-flex-direction: column;
            flex-direction: column;
  }

  .eael-img-accordion a:hover {
    -webkit-box-flex: 1;
    -webkit-flex: 1;
        -ms-flex: 1;
            flex: 1;
  }

  .eael-img-accordion a:hover .overlay {
    background-color: transparent;
  }
}

最佳答案

使用这个 CSS

.eael-img-accordion a:hover .overlay-inner div:nth-child(2) {
  display: none;
}

.eael-img-accordion .overlay-inner * {
  visibility: visible !important;
  opacity: 1 !important;
}

 .eael-img-accordion .overlay-inner h2 {
      visibility: visible !important;
      opacity: 1 !important;
      transform: none !important;
    }

注意:如果您不想要这种效果(上下),请在悬停时调整您的标题

关于javascript - 无需将鼠标悬停在 WordPress 中的 Image Accordion Gallery 上即可显示标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57970567/

相关文章:

Javascript 函数只运行一次?尝试多次使用相同的功能

javascript - 在 highcharts 中动态更新 yAxis 最小值和工具提示

javascript - 在选项卡之间切换时如何使用淡入淡出动画?

javascript - 使用 jQuery UI 从选择选项中获取值

javascript - 未选择日期选择器时隐藏两个特定的 div

html - INPUT 和 SELECT 元素自定义大小

javascript - 如何在 ng-repeat 中添加类

javascript - 如何在 Flash AS3 中构建自定义 slider ?

javascript - WordPress 下拉导航的 Z-Index 问题

css:隐藏的 overflow-x 和魔术鼠标/手势