pc 端时好时坏,时不时报错
经调试发现是异步请求问题,如果渲染前拿到数据就不会报错,否则就会报错。解决方案:改变渲染界面的代码位置,将渲染界面的代码放在异步请求的回调中去,拿到数据后在调用渲染
<!doctype html>
<!--[if lt IE 7 ]> <html lang="en" class="ie6"> <![endif]-->
<!--[if IE 7 ]> <html lang="en" class="ie7"> <![endif]-->
<!--[if IE 8 ]> <html lang="en" class="ie8"> <![endif]-->
<!--[if IE 9 ]> <html lang="en" class="ie9"> <![endif]-->
<!--[if !IE]><!-->
<html lang="en">
<!--<![endif]-->
<head>
<meta name="viewport" content="width = 1050, user-scalable = no" />
<script type="text/javascript" src="~/Scripts/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="~/Areas/Web/Scripts/modernizr.2.5.3.min.js"></script>
</head>
<body>
<div class="close" id="close"><img src="~/Areas/Web/Images/close.png" alt="" style="width:45px"></div>
<div style="background:rgba(0,0,0,0.7);width: 100%;height: 100%;position:fixed;top: 0;left: 0;z-index:999"></div>
<div class="flipbook-viewport">
<div class="container">
<div class="flipbook">
</div>
</div>
</div>
<script type="text/javascript">
//加载图片
var id = ''
var imgList = []
loadImgData()
function loadImgData() {
getId()
$.post('GetBookDetail', { id: id }, function (data) {
var fileList = data.Files
fileList.forEach(function (item) {
imgList.push(item.FileUrl)
})
//异步加载图片
var html = "";
for (var i = 0; i < imgList.length; i++) {
html += ' <div style="background:url(' + imgList[i] + ') center top no-repeat;background-size:100% 100%"></div>';
}
$(".flipbook").append(html);
yepnope({
test: Modernizr.csstransforms,
yep: ['../../Areas/Web/Scripts/turn.min.js'],
nope: ['../../Areas/Web/Scripts/turn.html4.min.js'],
both: ['../../Areas/Web/Content/basic.css'],
complete: loadApp
});
})
}
function loadApp() {
// Create the flipbook
var winWide = window.screen.width; //获取当前屏幕分辨率
if (winWide >= 1680) {
$('.flipbook').turn({
// Width
//width:922,
width: 1180,
// Height
height: 800,
// Elevation
elevation: 50,
// Enable gradients
gradients: true,
// Auto center this flipbook
autoCenter: true
});
} else{
$('.flipbook').turn({
// Width
//width:922,
width: 1000,
// Height
height: 620,
// Elevation
elevation: 50,
// Enable gradients
gradients: true,
// Auto center this flipbook
autoCenter: true
});
}
}
// Load the HTML4 version if there's not CSS transform
//获取URL中值
function getQueryString(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
var r = window.location.search.substr(1).match(reg);
if (r != null) return unescape(r[2]); return null;
}
function getId() {
id = getQueryString("id");
if (!id) return;
}
$('#close').click(function () {
window.location.href = "./Index";
})
</script>
</body>
</html>