js定时触发-----新订单提醒展示效果并提示音效

展示效果
js定时触发-----新订单提醒展示效果并提示音效_第1张图片


<style>
.add_blank{
    position: absolute;
    left: 14%;
    width: 34%;
    font-size: 32px;
    height: 66px;
    text-align: center;
    background: #ff9966;
    line-height: 67px;
    display: none;
}
style>


<div class="add_blank" >您有新的订单,请注意查看div>


    <script type="text/javascript">
        function timeout() {
            var res;
            $.ajax({
                url:'index.php?act=dingshi',
                type:'get',
                datatype:'text',
                async:false,
                success:function (data) {
                    res = data;
                }
            });
            return res;
        }
        var i=timeout();

        function hello() {
            $.ajax({
                url:'index.php?act=dingshi',
                type:'get',
                datatype:'text',
                async:false,
                success:function (result) {
                    if (result != i){
                        i = result;
                        $(".add_blank").show()
                        playSound();
                    }
                }
            });
        }
        setInterval("hello()",10000);
    script>
    
    <script type="text/javascript">
        $(function(){
            setInterval(function(){
                $(".add_blank").hide();
            },9000);
        });
    script>
    
    <script>
        var playSound = function () {
                var borswer = window.navigator.userAgent.toLowerCase();
                if ( borswer.indexOf( "ie" ) >= 0 )
                {
                    //IE内核浏览器
                    var strEmbed = '';
                    if ( $( "body" ).find( "embed" ).length <= 0 )
                        $( "body" ).append( strEmbed );
                    var embed = document.embedPlay;

                    //浏览器不支持 audion,则使用 embed 播放
                    embed.volume = 100;
                    //embed.play();这个不需要
                } else
                {
                    //非IE内核浏览器
                    var strAudio = ";

                    if($("#audioPlay").length<=0){
                        $( "body" ).append( strAudio );
                    }

                    var audio = document.getElementById( "audioPlay" );

                    //浏览器支持 audio
                    audio.play();
                }
            }
    script>

php代码

elseif ($_REQUEST['act'] == 'dingshi')
{
    //获取订单信息
    $count_order = $db->getOne(' SELECT COUNT(order_id) FROM ' . $ecs->table('order_info'));
    echo $count_order;
}

本来写在右下角弹出框,然后老有BUG,我就挪到头部,代码稳定。

```
```


你可能感兴趣的:(ecshop)