【问题标题】:jquery mobile page flash during transition after submit提交后过渡期间jquery mobile页面闪烁
【发布时间】:2011-09-25 05:22:22
【问题描述】:

我正在使用phonegap + jquery mobile,并且有一个可以工作的提交功能,提交后它会转换到另一个页面。这些页面是内页,例如 jquery mobile 使用的 data-role="pages"。问题是,在它最终转换到正确的内页之前,它会显示第一页,其中 data-role="pages" 设置为一瞬间。它不会阻止它工作我只是想阻止它闪烁第一页,因为它无关紧要,并让它正确地转换到正确的页面。这是我的javascript:

function addarticle(){


  var truth=$("#addform").validate().form()

if(truth==true){
var headlinetemp=$('#headline').val();
var articletemp=$('#article').val();
navigator.notification.activityStart();
$.ajax({
type:'POST',
url: "http://server.net/droiddev/backbone1/index.php/welcome/addarticle/",
data: { 'headline': headlinetemp, 'article': articletemp},
success:function(){
$('#headline').val('');
$('#article').val('');

 $.mobile.changePage($('#thanks'), { transition: "slide"});
//above is suppose to take you to thank you page without blinking the first page

 navigator.notification.activityStop();
},
error:function(xhr){
navigator.notification.activityStop();
alert('Error: Article was not added.');
}



});

}
else{alert('Please Correct the Form');}

}

这里是html

<!DOCTYPE html> 
<html> 
    <head> 
    <title>Page Title</title> 

    <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript" charset="utf-8" src="phonegap-1.0.0.js"></script>
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0b3/jquery.mobile-1.0b3.min.css" />
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.6.3.min.js"></script>
    <script type="text/javascript" src="http://code.jquery.com/mobile/1.0b3/jquery.mobile-1.0b3.min.js"></script>
     <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.8.1/jquery.validate.js"></script>
     <script type="text/javascript" charset="utf-8" src="main.js"></script>
     <style type="text/css">  #ajaxarea1{width:308px;
  display:block;
  margin:2px auto;
  height:50px;
  overflow:hidden;} 
  #errorarea ul li{ color:red;}
  .center{text-align:center;}
  </style>
</head> 

<body onload="init()" style=""> 

<!-- Start of first page -->
<div data-role="page" id="foo" data-title="Page Foo" data-theme="d" >

    <div data-role="header" data-theme="d" data-position="fixed">
        <h1>Foo</h1><a href="#" data-role="button" style="float:left;" data-rel="back" data-icon="arrow-l" data-iconpos="notext">Back</a>
    </div><!-- /header -->

    <div data-role="content">   
        <p>I'm first in the source order so I'm shown as the page.</p>  

        <p>View internal page called <a href="#bar" data-role="button" data-theme="d" data-transition="slide">bar</a></p>   
     <a href="#addart" data-role="button" data-theme="d" >Add Article</a>
    <!--<input type="text" id="numinput" placeholder="Enter a number.."></input>-->
    <div id="ajaxarea1"><p>This should change by hitting the button below</p></div>
    <button type="button" id="calcbtn" onclick="change_ajaxarea1()">Ajax call</button>

    </div><!-- /content -->

    </div>
</div><!-- /page -->


<!-- Start of second page -->
<div data-role="page" id="thanks" data-theme="d">

<p> testing thank you page!</p>
</div>



<div data-role="page" id="bar" data-theme="d" data-title="Page bar ya fool!">

    <div data-role="header" data-theme="d">
        <h1>Bar</h1>
        <a href="#" data-role="button" style="float:left;" data-rel="back" data-icon="arrow-l" data-theme="d" data-iconpos="notext">Back</a>
    </div><!-- /header -->

    <div data-role="content">   
        <p>I'm first in the source order so I'm shown as the page.</p>      
        <p><a href="#foo">Back to foo</a></p>   
        <a href="http://server.net">Test ajax</a>
        <div style="margin-top:10px;"><input type="text" placeholder="Testing placeholder.." style=""></input></div>
    </div><!-- /content -->

    <!--<div data-role="footer" data-position="fixed">
<p style="width:100%;margin:0 auto;display:block;padding:5px;">The footer is over here and i hope this doesnt get cut off. </p>
    </div> -->

    <!-- /footer -->
</div><!-- /page -->


<!-- Start of third(add) page -->
<div data-role="page" id="addart" data-theme="d" data-title="Page bar ya fool!">

    <div data-role="header" data-theme="d">
        <h1>Add article</h1>
        <a href="#" data-role="button" style="float:left;" data-rel="back" data-icon="arrow-l" data-theme="d" data-iconpos="notext">Back</a>
    </div><!-- /header -->

    <div data-role="content">   
        <form id="addform" style="text-align:center;"> <div id="errorarea"><ul>
            </ul></div><label for="Headline">Headline</label><br/><input type="text" name="Headline" title="Enter a title for the Headline at least 5 chars" class="required" id="headline" style="margin: 10px auto 20px auto;" placeholder="enter article headline.."></input>
<br/>   
 <label for="Article">Article</label><br/><textarea cols="40" rows="8" name="Article" id="article" class="required" title="Enter a article" name="textarea" style="margin: 10px auto 20px auto;" placeholder="enter article content.." id="textarea"></textarea>
        <br/>
        <input data-inline="true" style="display:inline-block;clear:both;text-align:center;" type="submit" value="Add Article"  onclick="addarticle()"></input>

        </form>



    </div>



    <!-- /content -->

    <!--<div data-role="footer" data-position="fixed">
<p style="width:100%;margin:0 auto;display:block;padding:5px;">The footer is over here and i hope this doesnt get cut off. </p>
    </div> -->

    <!-- /footer -->
</div><!-- /page -->

</body>
</html>

我希望我把我的问题说清楚了。谢谢

【问题讨论】:

  • 我在 Android 上遇到了同样的问题。它不会像在 iPhone 上那样闪烁旧页面。这是我的 android 应用程序的一个显示停止器。

标签: jquery ajax jquery-mobile cordova


【解决方案1】:

对于所有在页面加载时闪烁的,插入head标签:

<meta name="viewport" content="width=device-width,initial-scale=1.0, maximum-scale=1.0, maximum-scale=1.0, user-scalable=no" />;

这应该可以解决所有问题。

【讨论】:

    【解决方案2】:

    我认为这是一个已知问题:https://github.com/jquery/jquery-mobile/issues/455

    【讨论】:

      【解决方案3】:

      我在使用 JQuery Mobile 1.1.1 和 JQuery Core 1.7.1 时遇到了同样的问题。我通过升级到 JQuery Mobile 1.2.0 beta 和 JQuery Core 1.8.1 解决了这个问题。无需进行其他更改即可消除页面闪烁。

      【讨论】:

      • 我相信斯科特是正确的。我在运行 JQ 1.7.1 和 JQM 1.1.0 时遇到了同样的问题,但是更新到 Scott 提到的版本确实解决了相当烦人的闪烁问题。我需要做的就是下载新的 JS 文件,然后将它们换掉,工作就完成了!
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-16
      • 1970-01-01
      • 2012-06-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多