your programing

jquery fadeIn ()이 .html ()에서 작동하지 않는 이유는 무엇입니까?

lovepro 2020. 10. 15. 08:21
반응형

jquery fadeIn ()이 .html ()에서 작동하지 않는 이유는 무엇입니까?


확인란을 클릭하면 메시지가 천천히 페이드 인되기를 원합니다.

이 예제에서 .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');

이 문제를 분석 한 후 해결해야 할 코드는 페이드 아웃, HTML 변경 및 페이드 인을 사용하는 코드입니다.

$("#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');
    });

});

참고 URL : https://stackoverflow.com/questions/1490563/why-doesnt-jquery-fadein-work-with-html

반응형