Javascript 定期更新一本书';使用turn.js创建动态页面
我使用提供的示例创建了一个使用turn.js查看动态生成内容的示例 这是到目前为止我掌握的代码的一部分:Javascript 定期更新一本书';使用turn.js创建动态页面,javascript,jquery,ajax,turnjs,Javascript,Jquery,Ajax,Turnjs,我使用提供的示例创建了一个使用turn.js查看动态生成内容的示例 这是到目前为止我掌握的代码的一部分: <body> <div id="paper"> </div> </body> <script type="text/javascript"> $(window).ready(function() { $('#paper').turn({pages: 12}); }); $('#
<body>
<div id="paper">
</div>
</body>
<script type="text/javascript">
$(window).ready(function() {
$('#paper').turn({pages: 12});
});
$('#paper').bind('turning', function(e, page) {
var range = $(this).turn('range', page);
for (page = range[0]; page<=range[1]; page++)
addPage(page, $(this));
});
function addPage(page, book) {
// Check if the page is not in the book
if (!book.turn('hasPage', page)) {
// Create an element for this page
var element = $('<div />').html('Loading…');
// Add the page
book.turn('addPage', element, page);
// Get the data for this page
$.ajax({url: "getPage?filename=abcd&page="+page})
.done(function(data) {
element.html(data);
});
}
}
</script>
$(窗口).ready(函数(){
$('纸张')。翻({页:12});
});
$(“#纸张”).bind('turning',函数(e,第页){
变量范围=$(this).turn('range',page);
对于(page=range[0];page我通过继续进行以下更改,成功地完成了这项工作:
如果请求的png不可用,getPage现在返回
在调用页面中,我已更改代码以检查“loader”字符串,如果找到(这意味着png不可用),则调用setTimeout,在给定的时间后重试获取图像:
<body>
<div id="paper">
</div>
</body>
<script type="text/javascript">
$(window).ready(function() {
$('#paper').turn({pages: <s:property value='pages'/>});
});
$('#paper').bind('turning', function(e, page) {
var range = $(this).turn('range', page);
for (page = range[0]; page<=range[1]; page++)
addPage(page, $(this));
});
function addPage(page, book) {
// Check if the page is not in the book
if (!book.turn('hasPage', page)) {
// Create an element for this page
var element = $('<div />').html('Loading…');
// Add the page
book.turn('addPage', element, page);
// Get the data for this page
refreshPage(element,page);
}
}
function refreshPage( element, page )
{
$.ajax({url: "getPage?filename=<s:property value='filename'/>&page="+page})
.done(function(data) {
if( data.indexOf( "loader") > -1 )
{
setTimeout(function() {
refreshPage(element,page);
}, 5000);
}
element.html(data);
});
}
$(窗口).ready(函数(){
$('纸张')。翻({页:});
});
$(“#纸张”).bind('turning',函数(e,第页){
变量范围=$(this).turn('range',page);
用于(第页=范围[0];第-1页)
{
setTimeout(函数(){
刷新页面(元素,页面);
}, 5000);
}
html(数据);
});
}
也许有更好的方法来实现这一点,但至少它是有效的