简体   繁体   English

完全加载div后删除另一个div

[英]Remove another div when a div is completely loaded

I want to remove the loading image when the .flexslider div is loaded but the jquery ( $('flexslider').load() ) is not working. 我想在.flexslider div加载但jquery( $('flexslider').load() )无法正常工作时删除加载图像。 How to remove the image when the div is completely loaded? div完全加载后如何删除图像?

index.html index.html

<div class="flexslider">
        <div class="loadingDiv">
            <img src="images/banner0.jpg" style="visibility:hidden"/>
            <div class="showbox">

                <div class="loader">
                    <svg class="circular" viewBox="25 25 50 50">

                        <circle class="path" cx="50" cy="50" r="20" fill="none" stroke-width="2" stroke-miterlimit="10"/>                           
                    </svg>
                </div>
            </div>          
        </div>                                              
            <ul class="slides">
                <li><img src="images/banner1.jpg" width="1000px" height="500px" alt="" class="animated fadeInRightBig">
                    <div class="txtoverlay">
                        <div class="centralise">
                            <div class="verticalwrap">
                            </div>
                        </div>
                    </div>
                </li>
                <li><img src="images/banner2.png" alt="">
                    <div class="txtoverlay">
                        <div class="centralise">
                            <div class="verticalwrap">
                                <article>
                                </article>
                            </div>
                        </div>
                    </div>
                </li>
                <li><img src="images/banner3.png" alt="">
                    <div class="txtoverlay">
                        <div class="centralise">
                            <div class="verticalwrap">
                                <article>
                                </article>
                            </div>
                        </div>
                    </div>
                </li>
                <li><img src="images/banner4.jpg" alt="">
                    <div class="txtoverlay">
                        <div class="centralise">
                            <div class="verticalwrap">
                                <article>
                                </article>
                            </div>
                        </div>
                    </div>
                </li>
                <li><img src="images/banner5.jpg" alt="">
                    <div class="txtoverlay">
                        <div class="centralise">
                            <div class="verticalwrap">
                                <article>
                                </article>
                            </div>
                        </div>
                    </div>
                </li>
                <li><img src="images/banner6.jpg" alt="">
                    <div class="txtoverlay">
                        <div class="centralise">
                            <div class="verticalwrap">
                                <article>
                                </article>
                            </div>
                        </div>
                    </div>
                </li>

            </ul>
        </div>
    </div>

The jquery is: jQuery是:

$(document).ready(function(){

  $('.flexslider').load({
    $('loadingDiv').remove();
  });
});

I think the problem is $('.flexslider').load() function is not working. 我认为问题是$('.flexslider').load()函数无法正常工作。 Is there another way to work out this problem? 有没有其他方法可以解决此问题?

The first element that hides incorrectly specified, if you take an element by the class you need to specify '.' 隐藏第一个错误指定的元素,如果您按类接受一个元素,则需要指定“。”。 if you specify the class. 如果指定类。

Secondly, in the method "load" is transferred the closure and not the object 其次,在方法“负载”中传递闭包而不是对象

Try somethink like that 尝试这样的想法

  $('.flexslider').load(function(){
      $('.loadingDiv').remove();
  });

What you might be wanting is 您可能想要的是

<script src="https://code.jquery.com/jquery-1.12.0.min.js"></script>
<div class="flexslider">
    <div class="loadingDiv">
       somge gif here
    </div>                                              
    <ul class="slides">
        <li><img src="duck.jpg"></li>
        <li><img src="dog.jpg" alt=""></li>
        <li><img src="boar.jpg" alt=""></li>
        <li><img src="deer.png" alt=""></li>
    </ul>
</div>
<script>
    var imagesToLoad=  $('.slides img').length,
        loaded = 0;
    $('.slides img').bind('load', function() {
        loaded++;
    console.log('Loaded '+loaded+'/'+imagesToLoad);
    if(loaded===imagesToLoad)
        $('.loadingDiv').remove();
   });
</script>

Check this hope it can work.Load function expect data from server and replace with that div that you mentioned.I assume you do not want data from server so i have used simple index.html 检查此希望是否可以正常工作。加载功能期望来自服务器的数据并替换为您提到的div。我假设您不希望来自服务器的数据,所以我使用了简单的index.html

$(document).ready(function(){
   $( ".flexslider" ).load( "index.html" );
    setTimeout(function(){
   $(".loadingDiv").hide();
}, 3000);
});

According to documentation load event is not supposed to be used with divs. 根据文档,load事件不应与div一起使用。

The load event is sent to an element when it and all sub-elements have been completely loaded. 当加载事件和所有子元素都已完全加载时,会将加载事件发送到该元素。 This event can be sent to any element associated with a URL: images, scripts, frames, iframes, and the window object. 该事件可以发送到与URL关联的任何元素:图像,脚本,框架,iframe和window对象。

If this html is inside your root document, I recommend to use DOMContentLoaded instead. 如果此html在您的根文档中,则建议改用DOMContentLoaded。

$(function() {
    $('.loadingDiv').remove();
});

If you are using $.load to fetch remote html. 如果您使用$ .load来获取远程html。 You can pass a callback 您可以传递回调

$('div').load(url, function() {
   $('.loadingDiv').remove();
});

You can remove loadingDiv on $(window).load event. 您可以删除$(window).load事件上的loadingDiv $(window).load executes when complete page is fully loaded, including all frames, objects and images. $(window).load在完全加载完整页面(包括所有框架,对象和图像)时执行。 Hope this will help you. 希望这会帮助你。

$(window).load(function () {
    $('.loadingDiv').remove();
}); 

Update: For removing loadingDiv when flexslider div is completely loaded do like below. 更新:要在flexslider div完全加载时删除loadingDivflexslider执行以下操作。 Count the number of images in flexslider and after loading the last image hide the loadingDiv . 计算flexslider的图像数量,并在加载最后一个图像后隐藏loadingDiv

var images = $('.flexslider img'),
    imagesLength = images.length;

images.load(function () {
    if (! --imagesLength) {
       $('.loadingDiv').hide();
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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