【问题标题】:jquery animate text color opacityjquery动画文本颜色不透明度
【发布时间】:2014-03-16 00:16:57
【问题描述】:

我刚开始在一个网站上工作,并决定使用 jquery 的动画功能将页眉向下滑动。当它向下滑动时,会显示带有文本的 div。文本显示为灰色而不是黑色。我尝试过使用css,但没有运气。

谁能帮助并解释我需要做什么?我知道这与不透明度有关。

我想在不受其不透明度影响的标题 div 上显示一个 div。

index.php:

<center><div class="table"  id="header">
  <div class="row" id="body">grey</div>
</div></center>

Main.css:

html, body, div, span, h1, h2, h3, h4, h5, h6, p, a, img, form, table, tr, td {margin:0; padding:0; border:0; vertical-align:baseline; text-align:center;}
html, body {background-color:#EEEEEE;}
#header {min-width:80%; background-color:white;}
.table {display: table;}
.row {display: table-row;}
.cell {display: table-cell;}

index.css:

#header {height:500px; background:grey;}

index.js:

$(document).ready(function() {
$("#header").hide();
$("#body").hide();

$( "#header" ).animate({
    opacity: 0.25,
    left: "+=50",
    height: "toggle"
  }, 5000, function() {
  $("#body").show();
});

});

【问题讨论】:

  • 你有这个问题吗?无论如何...尝试将div设置为绝对位置,它不受over div的不透明度影响。
  • 不确定小提琴是什么。我应该将父 div 设置为绝对还是子?如果我将孩子设置为绝对,我应该定位父母吗?
  • “小提琴”(正确的专有名词:“小提琴”)指的是 JS Fiddle 或类似的现场演示。
  • 我只是在使用 jquery 和我自己的 js 文件

标签: javascript jquery text opacity


【解决方案1】:

尝试将opacity: 0.25改为opacity: 1.0

这里是一个例子:http://jsfiddle.net/maximgladkov/TRqaZ/

HTML

<div id="container">
    <div id="background"></div>
    <div id="text">Sample text</div>
</div>

CSS

#container {
    position: relative;
}

#background {
    background: grey;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

#text {
    opacity: 0;
    position: relative;
}

JS

$(document).ready(function() {
    $('#text').animate({
        opacity: 1.0
    }, 5000);
});

【讨论】:

  • 我想要不透明度。这样做时是否可以保持不透明度?
  • 现在我已经设置好了,所以它开始为灰色并随着不​​透明度过渡,但我不知道如何制作它,所以不透明度不会影响子 div
  • 不可能。您需要添加其他具有样式的子项:position: absolute 和您选择的背景颜色。之后,您应该为这个孩子的不透明度设置动画。
  • 谢谢。我想试试你所说的,看看能给我带来什么结果,但我很难按照你所说的去做。请给我一些关于如何尝试的说明,好吗?
  • 没有帮助。无论如何感谢您的帮助!如果我正在尝试的事情是不可能的,我必须寻找替代路径
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-01-06
  • 2011-11-22
  • 2016-03-26
  • 1970-01-01
  • 2010-09-25
  • 2011-10-06
  • 2016-04-24
相关资源
最近更新 更多