【问题标题】:Animate grow/shrink text w/o paragraph shift不带段落移位的动画增长/缩小文本
【发布时间】:2015-12-23 17:17:56
【问题描述】:

我有一段文本,其中段落中的某些单词或部分应转换为红色 --> 增加字体大小,几秒钟后恢复正常字体大小,同时保持红色突出显示。 (所有这些我都可以使用 CSS 转换和 Jquery 将类添加到 span 对象)但是 - 我的目标是在不导致周围段落文本随着字体大小增加和返回。

它应该如下图所示发生。我怎样才能让这种效果发挥作用并防止周围的文字移动/调整?

查看 SNIPPET FULL SCREEN - div 窗口的内联看起来错误

$('#svcdef p').each(function(index) {
  var li = $(this);

  setTimeout(function() {
    li.slideDown(900);
  }, 500 * index);

  setTimeout(function() {
    $('#svcdef p span').addClass('cfred');
  }, 3000);

  setTimeout(function() {
    $('#svcdef p span').removeClass('cfred');
    $('#svcdef p span').css('color', 'red');
  }, 8000);
});
#svcdef {
  text-align: left;
  height: 820px !important;
  color: #FFFFFF;
  text-align: justify;
  overflow: hidden;
  background-color: black;
}
#svcdef p {
  padding-left: 8px;
  padding-right: 8px;
}
#svcdef p span {
  transition: color 4s, font-size 2s ease-in-out;
}
.cfred {
  color: red;
  font-size: 24px;
}
#svc-content {
  height: 490px;
  float: left;
  width: 550px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div style="color:yellow;"><b>REPUTATION MANAGEMENT</b>
</div>
<style scoped="scoped">
  p {
    display: none;
  }
</style>
<br />
<div id="svcdef" class="modern-skin">
  <p><i><b>"It takes many good deeds to build a good reputation, and only one bad one to lose it."</b></i> • Benjamin Franklin
    <br>
    <br>
  </p>
  <p>Warren Buffet - Business magnate, Investor and philanthropist once stated "It takes 20 years to build a reputation and five minutes to ruin it. If you think about that, you’ll do things differently." Although a positive reputation for a brand and company
    does not in fact take 20 years to build, it is <span>possible</span> for a single instance of negative consumer engagement to immediately cause <span>20 years</span> or more of damage dependinging on the events that transpired and the manner in which
    the consumer shares the experience. Before the internet, many <span>companies were shielded</span> from negative events occuring with their potential customers, word of mouth remained the the primary means of communicating displeasure and the social
    network of other consumers that a negatively impacted customer could reach was curtailed and more localized. Thus damage could be more easliy mitigated or in some cases ignored.</p>
  <br />
  <p>some other paragraph
  </p>
  <br />
  <p>Yet, another useless paragraph</p>
</div>

【问题讨论】:

  • 顺便说一句,您的示例似乎无法正常运行。
  • @nicael 全屏运行代码 sn-p,窗口视图在查看时似乎搞砸了
  • 执行此操作的一种方法是将要扩展的文本放在设置为绝对的跨度类中,并将包含的段落设置为相对。您将不得不手动定位段落中的跨度。然后将样式应用于跨度。绝对定位使其脱离常规文档流,并且在文本放大时不应影响文档的其余部分。
  • @DannyGibas 我确实想到了 Danny,这是一种丑陋的实现方式,而动态添加这段代码的事实增加了一些扭曲。如果所有其他方法都失败并且没有更清洁的方法可以做到这一点,那么我会再次考虑该选项。我必须在段落中保持间距以表示超出 dom 顺序的跨度的“占用”空间。
  • 知道了。希望有人有更好的答案。我有兴趣自己了解一种更清洁的方法。

标签: jquery css css-transitions


【解决方案1】:

你的意思是这样的吗?

body {
  font-size: 25px;
}
boo{
   display:inline-block;
   transform:scale(1);
   transition: all 100ms linear;
}
boo:hover{
  color: red;
  transform:scale(2);
  transition: all 100ms linear;
}
<ol>
<li>This is the test sentence</li>
<li>This is the <boo>test (hover me ;)</boo> sentence</li>
<li>This is the test sentence</li>
</ol>

jQuery 示例:

var boo = 0;
setInterval(function(){
    boo==0?$("boo").addClass("booable"):$("boo").removeClass("booable");
    boo=!boo;
},100)
body {
  font-size: 25px;
}
boo {
  display: inline-block;
  transform: scale(1);
  transition: all 100ms linear;
}
.booable{
  color: red;
  transform: scale(2);
  transition: all 100ms linear;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ol>
  <li>This is the test sentence</li>
  <li>This is the <boo>test</boo> sentence</li>
  <li>This is the test sentence</li>
</ol>

【讨论】:

  • 这正是我想要的,除了它是一个悬停效果,我需要修改它以使用正在使用的 Jquery 方法,但如果我能让它工作,我'我会接受的!无论如何+1,谢谢!
  • 看看这个 jsfiddle 添加了你的代码,我得到了颜色偏移但没有变换。您可能对为什么该行为适用于 :hover 但不适用于 .addClass() 有一个解释? Fiddle link
  • @DMS 在您的示例中,删除 transform:scale(1);
猜你喜欢
  • 1970-01-01
  • 2018-03-12
  • 2012-10-30
  • 1970-01-01
  • 2012-06-02
  • 2019-08-01
  • 2020-08-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多