turn.js 异步请求图片资源,实现电子书翻页效果 报错 ”The page 1 dose not exist”

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>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值