Как я могу замаскировать видимость текста с перекрывающимся элементом, используя CSS - PullRequest
0 голосов
/ 17 февраля 2019

Если вы видите GIF, указанный ниже, текст появляется только после того, как он пересек Черную точку.До тех пор это невидимо.Это было сделано с использованием Flash, но как мы можем добиться этого с помощью CSS?

Logo GIF

Вот что я получил до сих пор:

@import url("https://fonts.googleapis.com/css?family=Ubuntu+Mono");
body {
  height: 100vh;
  background: #222;
  padding: 0;
  margin: 0;
  font-family: "Ubuntu Mono";
}

.ypn-logo {
  background: green;
  display: flex;
  flex-direction: row;
  position: relative;
  align-items: center;
  justify-content: center;
  padding: 10px;
  width: 220px;
  height: 220px;
  border-radius: 220px;
  z-index: 1;
}

.ypn-text {
  font-size: 3.5em;
  color: white;
  transition: all 1s cubic-bezier(0.86, 0, 0.07, 1);
  margin-left: -80px;
  z-index: 0;
}

.ypn-text:before {
  background: red;
  content: "";
  position: absolute;
  width: 180px;
  height: 180px;
  border-radius: 180px;
  z-index: -1;
  transition: all 1s cubic-bezier(0.86, 0, 0.07, 1);
  top: 30px;
  left: 10px;
}

.ypn-logo:hover>.ypn-text:before {
  left: 50px;
}

.ypn-text:after {
  background: #222;
  content: "";
  position: absolute;
  width: 50px;
  height: 50px;
  border-radius: 180px;
  transition: all 1s cubic-bezier(0.86, 0, 0.07, 1);
  top: 95px;
  left: 130px;
  z-index: 1;
}

.ypn-logo:hover>.ypn-text:after {
  left: 60px;
}

.ypn-logo:hover>.ypn-text {
  margin-left: 80px;
}
<div class="ypn-logo">
  <div class="ypn-text">RUN</div>
</div>

Я думал сделать div и зафиксировать его правую границу с центральной осью точки в середине, но это также скрывает зеленый и красный элементы.Есть ли способ просто заблокировать текстовый элемент, но не другие элементы?

@import url("https://fonts.googleapis.com/css?family=Ubuntu+Mono");
body {
  height: 100vh;
  background: #222;
  padding: 0;
  margin: 0;
  font-family: "Ubuntu Mono";
}

.ypn-logo {
  background: green;
  display: flex;
  flex-direction: row;
  position: relative;
  align-items: center;
  justify-content: center;
  padding: 10px;
  width: 220px;
  height: 220px;
  border-radius: 220px;
  z-index: 1;
}

.ypn-text {
  font-size: 3.5em;
  color: white;
  transition: all 1s cubic-bezier(0.86, 0, 0.07, 1);
  margin-left: -80px;
  z-index: 0;
}

.ypn-before {
  background: red;
  content: "";
  position: absolute;
  width: 180px;
  height: 180px;
  border-radius: 180px;
  z-index: -1;
  transition: all 1s cubic-bezier(0.86, 0, 0.07, 1);
  top: 30px;
  left: 10px;
}

.ypn-logo:hover>.ypn-before {
  left: 50px;
}

.ypn-after {
  background: #222;
  content: "";
  position: absolute;
  width: 50px;
  height: 50px;
  border-radius: 180px;
  transition: all 1s cubic-bezier(0.86, 0, 0.07, 1);
  top: 95px;
  left: 130px;
  z-index: 1;
}

.ypn-logo:hover>.ypn-after {
  left: 60px;
}

.ypn-logo:hover>.ypn-text {
  margin-left: 80px;
}

.ypn-after:after {
  width: 130px;
  background: black;
  height: 3em;
  content: '';
  position: absolute;
  left: -100px;
}
<div class="ypn-logo">
  <div class="ypn-before"></div>
  <div class="ypn-text">YPN</div>
  <div class="ypn-after"></div>
</div>

Ответы [ 2 ]

0 голосов
/ 17 февраля 2019

Вот идея, где вы можете положиться на один элемент и рассмотреть анимацию ширины / поля:

.box {
  font-size: 50px;
  font-weight: bold;
  line-height: 1em;
  display: inline-flex;
  justify-content:flex-end;
  overflow:hidden;
  white-space:nowrap;
  border-radius:1em 0 0 1em;
  
  background: radial-gradient(#000 0.48em, transparent 0.5em) left/1em 1em no-repeat;
  
  width:0;
  margin-left:200px;
  padding: 5px 1em 5px 0;
  transition:1s;
}

body:hover .box {
  width:200px;
  margin-left:0px;
  padding: 5px 0 5px 1em;
}
<div class="box">
  some text
</div>

Чтобы избежать установки определенной ширины, вы можете отрегулировать выравнивание и рассмотреть max-width:

.container {
  text-align:right;
  width:500px;
}

.box {
  font-size: 50px;
  font-weight: bold;
  line-height: 1em;
  display: inline-flex;
  justify-content:flex-end;
  overflow:hidden;
  white-space:nowrap;
  border-radius:1em 0 0 1em;
  
  background: radial-gradient(#000 0.48em, transparent 0.5em) left/1em 1em no-repeat;
  
  max-width:0;
  padding: 5px 1em 5px 0;
  transition:max-width 1s,padding 0s 1s;
}

body:hover .box {
  max-width:100%;
  padding: 5px 0 5px 1em;
  transition:max-width 1s;
}
<div class="container">
<div class="box">
  some text
</div>
</div>
0 голосов
/ 17 февраля 2019

Вы можете сделать текст дочерним для элемента с цветом фона.Затем создайте маску, создав элемент с точкой и элементом div, установленным на цвет фона родительского элемента.Сделайте родительский элемент overflow:hidden таким образом, чтобы цветная область не была видна при перемещении, чтобы раскрыть текст.

$('.overlay').on('click', function() {
  $(this).toggleClass('hidden');
});

$(window).on('load', function() {
  $('.overlay').removeClass('hidden');
});
body {
  background: red;
}

.container {
  width: 80%;
  height: 60px;
  border-radius: 60px;
  background: white;
  overflow: hidden;
  margin: 20px auto;
  position: relative;
}

.overlay {
  width: 100%;
  height: 100%;
  background: white;
  transition: left 2s ease-out;
  position: absolute;
  top: 0;
  left: calc( -100% + 60px);
}

.overlay.hidden {
  left: 0;
}

.overlay::after {
  content: '';
  background: black;
  height: 60px;
  width: 60px;
  border-radius: 60px;
  position: absolute;
  right: 0;
  top: 0;
}

.text {
  font-size: 50px;
  line-height: 60px;
  width: 100%;
  text-align: center;
}

p {
text-align: center;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="container">
  <div class="text">ezoom</div>
  <div class="overlay hidden"></div>
</div>

<p> click the circle to toggle the animation</p>


РЕДАКТИРОВАТЬ:
После использования вышеуказанного принципа, вот окончательный код для нужного эффекта:

@import url("https://fonts.googleapis.com/css?family=Ubuntu+Mono");
body {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
  padding: 0;
  margin: 0;
  background: #222;
  font-family: "Ubuntu Mono";
}

.ypn-logo {
  background: green;
  display: flex;
  flex-direction: row;
  position: relative;
  align-items: center;
  justify-content: center;
  padding: 10px;
  width: 220px;
  height: 220px;
  border-radius: 220px;
}

.ypn-before {
  background: red;
  content: '';
  overflow: hidden;
  width: 180px;
  height: 180px;
  border-radius: 180px;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  position: relative;
  left: -20px;
  transition: all 1s cubic-bezier(0.86, 0, 0.07, 1);
}

.ypn-text {
  background: none;
  position: absolute;
  left: 20px;
  font-size: 3.2em;
  color: #ddd;
  transition: all 1s cubic-bezier(0.86, 0, 0.07, 1);
}

.ypn-dot {
  width: 200px;
  height: 200px;
  position: relative;
  background: red;
  left: -35px;
  transition: all 1s cubic-bezier(0.86, 0, 0.07, 1);
}

.ypn-dot:after {
  content: '';
  position: absolute;
  background: #222;
  width: 60px;
  height: 60px;
  border-radius: 60px;
  top: 70px;
  right: -25px;
  transition: all 1s cubic-bezier(0.86, 0, 0.07, 1);
}

.ypn-logo:hover>.ypn-before {
  left: 20px;
}

.ypn-logo:hover>.ypn-before .ypn-dot {
  left: -135px;
}

.ypn-logo:hover>.ypn-before .ypn-text {
  left: 80px;
}
<div class="ypn-logo">
  <div class="ypn-before">
    <div class="ypn-text">RUN</div>
    <div class="ypn-dot"></div>
  </div>
</div>

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...