JQUERY刷新闪烁
JQUERY refresh blinking
我有一小段代码,应该刷新页面的一部分。刷新部分工作得很好,只是我注意到每次刷新它都会闪烁。有什么建议可以消除眨眼吗?
<html>
<head>
<title>test</title>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
(function($)
{
$(document).ready(function()
{
$.ajaxSetup(
{
cache: false,
beforeSend: function() {
$('#content').hide();
$('#loading').show();
},
complete: function() {
$('#loading').hide();
$('#content').show();
},
success: function() {
$('#loading').hide();
$('#content').show();
}
});
var $container = $("#content");
$container.load("ajaxstatus.php");
var refreshId = setInterval(function()
{
$container.load('ajaxstatus.php');
}, 9000);
});
})(jQuery);
</script>
</head>
<body>
<div id="wrapper">
<div id="content"></div>
</div>
</body>
</html>
这是php文件;
<?php
echo "1test<BR>";
echo "32333<BR>";
echo "2dddd2111<BR>";
echo "2dddcvbcvbd2111<BR>";
echo "2dsdfbddd2111<BR>";
?>
对代码做一个小改动就修复了它。希望其他人能从中找到用处。
<html>
<head>
<title>test</title>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(function() {
startRefresh();
});
function startRefresh() {
setTimeout(startRefresh,1000);
$.get('ajaxstatus.php', function(data) {
$('#content').html(data);
});
}
</script>
</head>
<body>
<div id="wrapper">
<div id="content"></div>
</div>
</body>
</html>
尝试将fast
作为参数传递给hide()和show()函数,如
success: function() {
$('#loading').hide('fast');
$('#content').show('fast');
}
去掉.show()
,用.hide()
代替.html()
。显示隐藏会导致浏览器重新启动两次,而HTML只会导致一次。
你可以使用jquery的div和。get从你网站的另一个页面获取数据。
可以使用setTimeOut(function, time)
$(function() {
startRefresh(); });
function startRefresh() {
setTimeout(startRefresh,1000);
$.get('pagelink.php', function(data) {
$('#content_div_id').html(data);
}); }
相关文章:
- 强制模板刷新ember.js
- 如何通过ajax刷新JSF填充的javascript变量
- 为什么在单独的函数中应用时转换会闪烁/断断续续(D3)
- 使用jQuery以红色和黑色闪烁文本
- 如何解决Yii中的页面刷新问题
- Jquery提交表单而不刷新
- 刷新页面后会出现警报
- 刷新后保留对网页的更改
- 如何在不刷新页面的情况下更新显示框
- 重定向时角度刷新浏览器
- ajax html javascript页面刷新无闪烁问题
- 刷新闪烁时的随机背景(汤博乐)
- 正在刷新没有树的jstree'闪烁'铬
- 流星 - 页面刷新导致在为路由器获取数据时闪烁
- 停止 iframe 刷新时闪烁
- 在 jQuery 中是否可以在不使页面闪烁的情况下自动刷新?就像在脸书中一样
- 刷新iframe而不闪烁
- JQUERY刷新闪烁
- HTML5画布在刷新时闪烁
- 如何避免自动刷新后的闪烁