doushanmo7024 2015-05-12 09:18
浏览 87
已采纳

Yii2当Bootstrap模态仍在加载时加载页面/图像

I have this modal:

<?php
    echo Html::button(
        'Create New Staff',
        [
            'value' => Url::to(['create-new-staff']),
            'class' => 'btn btn-success btn-create',
            'id' => 'modalButton'
        ]);

    Modal::begin(['id' => 'modal']);
    echo "<div id='modalContent'></div>";     
    Modal::end();
?>  

Here's my sample loading indicator image:

<img src="http://dkclasses.com/images/loading.gif" id="loading-indicator" style="display:none" />

When I click the modal button, I want to display a loading screen or image when the modal is still loading instead of just plainly waiting for the modal to load. I tried this:

<script type="text/javascript">
    $("modalButton").click(function(event) {
        $.post( "/echo/json/", { delay: 2 } );
        $(document).bind("ajaxSend", function(){
            $("#loading-indicator").show();
            }).bind("ajaxComplete", function(){
            $("#loading-indicator").hide();
            $("#modalContent").show();
         });
    });
</script>

I based that script in this fiddle.

And I also tried those I have searched in the internet. None of them worked. I think it's because I am using Yii. I'm not sure. How do I achieve this?

  • 写回答

2条回答 默认 最新

  • dousongqiang2585 2015-05-15 06:06
    关注

    Figured it out:

    $('#modalButton').click(function (){
        $('#modal').find('#modalContent').html("")
            .load($(this).attr('value'), function(){
                var thisModal = $('#modal');
                setTimeout(function(){
                    thisModal.modal('show');
                    $("#loading-indicator").hide();
                }, 1000);
            });
        $("#loading-indicator").show();
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)