单击时如何关闭此工具提示

时间:2019-06-18 11:15:48

标签: jquery css

我出现一个工具提示。为了更方便地在移动设备上使用,我希望用户单击时能够将其关闭。

我尝试在click事件上触发模糊事件。 但是,这并不能解决问题。 我知道点击事件返回false。但是,不确定如何修改它,以便我仍然可以单击工具提示,将其强制关闭。

$j = jQuery;

$j(function() {
  $j(".help-tip").click(function(event) {
    return false;
  });
});
.cell {
  width: 60%;
  max-width: 70%;
}

#product-form .stock label {
  position: relative;
  color: #2fcc71;
  background-color: #fff;
  font-size: 1.5rem;
  text-align: center;
  height: 80px;
  line-height: 80px;
  display: block;
  cursor: pointer;
  border: 3px solid #2fcc71;
  border-radius: 10px;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}

#product-form .stock label span {
  display: inline-block !important;
  color: #2fcc71;
  background-color: #fff;
  font-size: 1rem;
  text-align: left;
  height: 10px !important;
  line-height: 10px !important;
}

#product-form .stock input:checked+label {
  border: 3px solid #333;
  background-color: #2fcc71;
  color: #fff;
}

#product-form .stock input:checked+label:after {
  content: "\2713";
  width: 40px;
  height: 40px;
  line-height: 40px;
  border-radius: 100%;
  border: 2px solid #333;
  background-color: #2fcc71;
  color: #fff;
  z-index: 999;
  position: absolute;
  top: -10px;
  right: -10px;
}

#product-form .stock input {
  display: none;
}

.help-tip {
  position: absolute;
  top: 50px;
  right: -30px;
  text-align: center;
  background-color: #BCDBEA;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  font-size: 14px;
  line-height: 26px;
  cursor: default;
}

.help-tip:before {
  content: '?';
  font-weight: bold;
  color: #fff;
}

.help-tip:hover p {
  display: block;
  transform-origin: 100% 0%;
  -webkit-animation: fadeIn 0.3s ease-in-out;
  animation: fadeIn 0.3s ease-in-out;
}

.help-tip p {
  /* The tooltip */
  display: none;
  text-align: left;
  background-color: #1E2021;
  padding: 20px;
  width: 300px;
  position: absolute;
  border-radius: 3px;
  box-shadow: 1px 1px 1px rgba(0, 0, 0, 0.2);
  right: -4px;
  color: #FFF;
  font-size: 13px;
  line-height: 1.4;
  z-index: 999;
}

.help-tip p:before {
  /* The pointer of the tooltip */
  position: absolute;
  content: '';
  width: 0;
  height: 0;
  border: 6px solid transparent;
  border-bottom-color: #1E2021;
  right: 10px;
  top: -12px;
}

.help-tip p:after {
  /* Prevents the tooltip from being hidden */
  width: 100%;
  height: 40px;
  content: '';
  position: absolute;
  top: -40px;
  left: 0;
}


/* CSS animation */

@-webkit-keyframes fadeIn {
  0% {
    opacity: 0;
    transform: scale(0.6);
  }
  100% {
    opacity: 100%;
    transform: scale(1);
  }
}

@keyframes fadeIn {
  0% {
    opacity: 0;
  }
  100% {
    opacity: 100%;
  }
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form id="product-form">
  <section class="stock">
    Choose your material:
    <input type='radio' name='radio_stock' id='5' value='5'>
    <label class='5-label cell' for='5'>
         ABC
         <div class='help-tip'>
            <p>tooltip ABC</p>
         </div>
      </label>
    <input type='radio' name='radio_stock' id='1' value='1'>
    <label class='1-label cell' for='1'>
         DEF)
         <div class='help-tip'>
            <p>Tooltip DEF</p>
         </div>
      </label>
  </section>
</form>

出现工具提示时,单击它即可使其消失。

0 个答案:

没有答案