简体   繁体   English

jQuery animation() 中的隐藏文本不显示

[英]Hidden text in jQuery animation() doesn't show up

HTML: HTML:

<div>
    <code id="code">about</code>
    <code id="hid-code"></code>   
</div>

CSS: CSS:

body {
    background-color: black;
 }
div {
    background-color: transparent;
    width: 100px;
    height: 1.1em;
    text-align: left;
    border: 1px solid #91e0ee;
    margin: 3px;
    font-size: 15px;
 }
#code {
    padding: 2%;
    font-variant: small-caps;
    color: #91e0ee;
    vertical-align: top;
 }
#hid-code {
    font-variant: small-caps;
    color: #91e0ee;
    display: none;
 }

JS: JS:

// STRING TO HIDE
var hidCode = ": who is index?";

// APPEND hidCode TO #hid-code
document.getElementById('hid-code').innerHTML = hidCode;

// jQuery ANIMATION
$("div").click(function() {
    // STYLE ANIMATION
    $("div")
        .animate({ width: "20%", fontSize: "18px" }, "slow" )
        .animate({ borderLeftWidth: "5px", }, 500 );
    // HIDDEN STRING SHOWS UP
    $("hid-code").appendTo('#code').show("slow");
})

The string added to the variable hidCode should show up after the // STYLE ANIMATION .添加到变量hidCode的字符串应显示在// STYLE ANIMATION I used the display: none to hide the string in the hid-code id.我使用display: none来隐藏隐藏hid-code ID 中的字符串。 Therefore, if I append() it to the code id, and use show() , it should work, but nothing happens.因此,如果我append()append()code ID,并使用show() ,它应该可以工作,但没有任何反应。 Any tip?任何提示?

You need to put # in $("hid-code") , because you have defined it as an id.您需要将#放入$("hid-code") ,因为您已将其定义为 id。 So, it has to be: $("#hid-code") for jQuery to find it.因此,它必须是: $("#hid-code")以便 jQuery 找到它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM