如何将淡入淡出效果添加到jquery追加

时间:2016-08-14 16:51:30

标签: javascript jquery html css

我试图为使用jquery创建的div添加淡入/淡出效果,但我似乎无法弄明白。有什么想法吗?

继承我目前的代码:

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();
      });

提前致谢,

斯科特。

3 个答案:

答案 0 :(得分:1)

将其包裹在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());

答案 1 :(得分:0)

广告内联样式display: none到您的div。然后只需选择它并在其上调用fadeOut

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

答案 2 :(得分:0)

尝试此代码:

/opt/apache-tomee-webprofile-7.0.1
相关问题