带有 javascript 的 jquery 移动闪屏 [英] jquery mobile splash screen with javascript

查看:23
本文介绍了带有 javascript 的 jquery 移动闪屏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图避免在启动画面中使用它,因为它不适用于所有设备以及其他原因:

所以我尝试改用它,它工作正常,直到它滑入新页面,然后再次像启动画面一样处理(例如 当计时器到期时它变为空白 - 在这种情况下为 4秒).如何停止/限制此行为,以便 changePage 仅包含在启动页面中?

<div data-role="page" id="splash"><div class="splash"><img src="startup.jpg" alt="启动图片"/><script type='text/javascript'>//<![CDATA[$(window).load(function(){$(函数(){setTimeout(hideSplash, 4000);});函数隐藏溅(){$.mobile.changePage("#home", "淡出");}});//]]>

<div data-role="page" id="home"><div data-role="header" data-backbtn="false"><h1></h1>

<div data-role="内容">

解决方案

这里的好主意就是我的想法.使用单页而不是多页(多个数据角色=页面).对于 index.html 或 index.php 或其他.放置您的启动页面.原因我稍后会解释.

<块引用>

index.html

<!-- 首先包含所有jquery的东西--><script src="app.js"></script><!-- 外部脚本,因为我们可以将它包含在每个页面中--><身体><div data-role="page" id="splash"><div class="splash"><img src="startup.jpg" alt="启动图片"/>

<块引用>

app.js

$(document).on('pageinit','#splash',function(){//.on() 方法确实需要 jQuery 1.7 + 但这将允许您只拥有包含的代码在#splash 页面初始化时运行.设置超时(功能(){$.mobile.changePage("home.html", "淡出");}, 4000);});

好的,所以我这样做是因为假设您有导航菜单,并且您想将人们送回主页.您不必再次显示启动页面.您可以链接到 home.html.拆分页面有助于保持 dom 更精简.我希望这会有所帮助.

I'm seeking to avoid using this for the splash screen, because it does not work on all devices and for other reasons:

<link rel="apple-touch-startup-image" href="img/splash.png" />

So I'm trying to use this instead and it works fine until it slides into a new page, which is then treated like the splash screen again (e.g. it goes blank when the timer expires - in this case 4 seconds). How can I stop/restrict this behavior, so that changePage remains contained in splash page only?

<body>
 <div data-role="page" id="splash"> 
  <div class="splash">
    <img src="startup.jpg" alt="startup image" />

<script type='text/javascript'>//<![CDATA[ 
            $(window).load(function(){
            $(function() {
                setTimeout(hideSplash, 4000);
                        });

            function hideSplash() {
            $.mobile.changePage("#home", "fade");
            }


            });//]]>  
        </script>

  </div>
 </div>

 <div data-role="page" id="home"> 
   <div data-role="header" data-backbtn="false">
    <h1></h1>
   </div>
   <div data-role="content">

   </div>
 </div>
</body>

解决方案

Good idea here is what I'm thinking. Use single pages instead of multi page(multiple data-role=page). For index.html or index.php or whatever. Put your splash page. The reason for this I will explain later on.

index.html

<head>
    <!-- First include all jquery stuff -->
    <script src="app.js"></script><!-- external script because we can just include it in every page -->
</head>
<body>
    <div data-role="page" id="splash"> 
        <div class="splash">
            <img src="startup.jpg" alt="startup image" />
        </div>
    </div>
</body>

app.js

$(document).on('pageinit','#splash',function(){ // the .on() method does require jQuery 1.7 + but this will allow you to have the contained code only run when the #splash page is initialized.
    setTimeout(function(){
        $.mobile.changePage("home.html", "fade");
    }, 4000);
});

Ok so I did it this way because lets say you have navigation menu and you want to send people back to home page. You won't have to show the splash page again. You can just link to home.html. Also splitting up your pages helps keep the dom leaner. I hope this helps.

这篇关于带有 javascript 的 jquery 移动闪屏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
其他开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆