jquery fadein ()가 .html ()와 함께 작동하지 않는 이유는 무엇입니까?

StackOverflow https://stackoverflow.com/questions/1490563

  •  18-09-2019
  •  | 
  •  

문제

확인란을 클릭하면 메시지가 천천히 사라지는 것을 원합니다.

이 예에서 .fadein ()이 작동하지 않는 이유는 무엇입니까?

HTML :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="content-type" content="text/html;charset=utf-8"/>
        <title>Text XHTML Page</title>
        <link href="css/main.css" rel="stylesheet" type="text/css" media="all"/>
        <script type="text/javascript" src="http://www.google.com/jsapi"></script>
        <script type="text/javascript" src="javascript/main.js"></script>       
    </head>
<body>
    <div class="checkboxList">
        <div class="title">Languages:</div>
        <div class="row"><input class="checkbox" type="checkbox"/><span class="label">Ruby</span></div>
        <div class="row"><input type="checkbox"/><span class="label">PHP</span></div>
        <div class="row"><input type="checkbox"/><span class="label">C#</span></div>
        <div class="row"><input type="checkbox"/><span class="label">Python</span></div>
        <div class="row"><input type="checkbox"/><span class="label">JavaScript</span></div>
    </div>
    <p id="message"></p>
</body>
</html>

자바 스크립트 :

google.load("jquery", "1.3.2");

//run when page is loaded
google.setOnLoadCallback(function() {

    $('.checkboxList .row').css('color','red');
    $('.checkboxList input').attr('checked', true);
    $('.checkboxList input').bind('click', function() {
        $('#message').html("You clicked on a checkbox.").fadeIn('slow');
    });

});
도움이 되었습니까?

해결책

#MESSAGE 요소가 표시되기 때문에 FadeIn은 수행되지 않습니다.

$('#message').hide().html("You clicked on a checkbox.").fadeIn('slow');

다른 팁

이 문제를 분석 한 후, 내가 해결 해야하는 것은 내 코드이며, Fadeout을 사용하고 HTML을 변경하고 Fadein을 사용하는 내 코드입니다.

$("#div_big_picture").fadeOut('slow',function(){
    $(this).html("<img src='" + str_to_load + "' height='800px' />")
}).fadeIn("slow");

왜 그런지 모르겠지만 나는 전에 이것을 연쇄시키는 데 어려움을 겪었습니다. 이 우아한 코드를 사용하여 원하는 효과를 얻을 수 있습니다.

google.load("jquery", "1.3.2");

//run when page is loaded
google.setOnLoadCallback(function() {

    $('.checkboxList .row').css('color','red');
    $('.checkboxList input').attr('checked', true);
    $('.checkboxList input').bind('click', function() {
        $('#message').hide(); //just in case
        $('#message').html("You clicked on a checkbox.");
        $('#message').fadeIn('slow');
    });

});
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top