简体   繁体   English

导航时加载GIF图像

[英]loading GIF image while navigating

is there any way that loading GIF image while onclick and simultaneously, navigation should happen. 有什么方法可以在单击和同时加载GIF图像时进行导航。

i tried using jquery but loader animations are not happening while page navigates in some mobile browser, is there a solution using ajax to overcome that problem? 我尝试使用jquery,但在某些移动浏览器中进行页面导航时,加载程序动画没有发生,是否有使用ajax的解决方案来解决该问题?

The best way to do is is to use AJAX to load new content. 最好的方法是使用AJAX加载新内容。 What you can do is have a button which when clicked clears the html of the initial page and reloads content for the other html page. 您可以做的是有一个按钮,单击该按钮会清除初始页面的html,并重新加载其他html页面的内容。

Lets say you have the page's HTML contents in a div called #div and there's a button called #button which when clicked takes you to the new page. 假设您在名为#div的div中包含了页面的HTML内容,并且有一个名为#button的按钮,单击该按钮会将您带到新页面。 What you can do now is that whenever #button is clicked, you can clear the HTML contents of the current div, load the HTML of the new page (and while it loads you can display the GIF image) and then populate the div with the HTML of the new page. 您现在可以做的是,只要单击#button,就可以清除当前div的HTML内容,加载新页面的HTML(并且在加载新页面时可以显示GIF图像),然后在div中填充新页面的HTML。

$("#button").click(function() {

   //till the time the post function below doesn't return the following image will be displayed     
   $("#div").html('<img src = "images/ajax-loader.gif" />');

   $.post("get_html.php", function (data) {

    //get the new HTML content
    $("#div").html(data);

   });


});

This is just an example, if you are more specific in what you need, maybe I could write code suited to your needs. 这只是一个例子,如果您对需求有更具体的说明,也许我可以编写适合您需求的代码。

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

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