<script>
            function notiFy(msg) {
                $('#appalertmessage').html(msg).hide().fadeIn(function() {
                    var self = $(this);
                    setTimeout(function() {
                        self.fadeOut()
                    },
                    1000)
                }).css('left', ($('body').width() - $('#appalertmessage').width()) * .5)
            }
        </script>
这段JS代码有什么用?高手求讲解

解决方案 »

  1.   

    调用notiFy的时候 在屏幕中间淡入id=appalertmessage的消息显示框,显示消息msg 
      

  2.   


    function notiFy(msg) {
      $('#appalertmessage').html(msg)//id为appalertmessage的元素加载内容 msg
        .hide()//隐藏元素
        .fadeIn(function() {//显示元素   完成后执行如下函数
            var self = $(this);
            setTimeout(function() {
    self.fadeOut()//一秒后隐藏元素
    },1000)
    })
    .css(//设置元素的距离页面左边距离  为body宽度-元素宽度   乘以0.5  居中显示
    'left', 
    ($('body').width() - $('#appalertmessage').width()) * 0.5
    )
    }