简体   繁体   中英

How to add a fade effect to a jquery append

I'm trying to add a fade in / fade out effect to a div that is created using jquery but I cant seem to figure it out. Any ideas ?

Heres my current code :

if (sessionStorage.getItem('hintOnce') !== 'true') {
        $('body').append('<div class="control-hint"><p> Use the controls to improve your browsing experience. </p><div class="close">X</div></div>')
        sessionStorage.setItem('hintOnce','true');
        }

        $('.control-hint').on('click',function(){
        $('.control-hint').hide();
      });

Thanks in advance,

Scott.

将其包装在jq对象中,然后将其隐藏,然后使其淡入:

$('body').append($('<div class="control-hint"><p> Use the controls to improve your browsing experience. </p><div class="close">X</div></div>').hide().fadeIn());

Ad inline style display: none to your div. Then just select it and call fadeOut on it.

$('body').append('<div class="control-hint" style="display: none"><p> Use the controls to improve your browsing experience. </p><div class="close">X</div></div>');
$('.control-hint').fadeOut();

试试这个代码:

$('<div class="control-hint"><p> Use the controls to improve your browsing experience. </p><div class="close">X</div></div>').appendTo("body").hide().fadeIn(300);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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