前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >ios中iframe的scroll滚动事件替代方法

ios中iframe的scroll滚动事件替代方法

作者头像
deepcc
发布2018-07-05 15:12:20
1.9K0
发布2018-07-05 15:12:20
举报
文章被收录于专栏:deepccdeepccdeepcc

在公众号的开发中,遇到ios中iframe的scroll滚动事件失效,在此做下记录。

因为接口获取的数据必须放在iframe中展示,滚动到底部按钮变亮,如图:

代码如下:

<!DOCTYPE html>
<html>
<head>
    <title>贷款合同</title>
    <% include ../include/header.html %>
</head>
<body style="background: #eee;">
<header><a href="javascript:history.back(-1)" class="return_a">返回</a>贷款合同</header>
<form action="" method="post" class="user-info-form" id="user-info-form">
    <!-- 第三步 begin -->
    <div class="three-step region-box main" >         
 
        <div class="read-agreement-box">
            <!-- <div class="h3">贷款合同</div> -->
            <div class="bd">
                <div class="iframe" >
                    <iframe src="" id="iframeContract" width="100%" frameborder="0" scrolling="auto"></iframe>
                </div>
            </div>
        </div>
        <button  class="btn-view btn" disabled="disabled" v-on:click="clickFn()">签约</button>
        
    </div>
    <!-- 第三步 end -->
</form>
</body>
<style>
    .iframe{height: 500px;width: 100%;overflow-x: hidden;overflow-y: auto;}
</style>
    <% include ../include/footer.html %>
<script>
    $(function () {

     new Vue({
        el:'.main',
        data:{
            iframeH:500
        },
        methods:{
            scrollFn:function(e){
                $(document.getElementById('iframeContract').contentWindow).scroll(function(event) {
                    /* Act on the event */
                    var fh = $('#iframeContract').height();
                    var docH = $(this).height();
                    var t = $(this).scrollTop();

                    if(docH-t-fh<=0){
                        $('.btn-view').removeAttr('disabled');
                    }
                });
                
            },
            clickFn:function(){
                this.$http.post(window._appPath +'contract/confirm.do',{
                    openId:$.cookie('openId')
                },{
                    emulateJSON:true
                }).then(function(res){
                    var data = res.data; 
                    if(data.code==0){
                        CommonUtil.redirectUrl('loan/loan_step6.html');
                    }else{
                        $.alert(data.message)
                    }
                })
            },
            getFn:function(){
                this.$http.post(window._appPath +'contract/html.do',{
                    openId:$.cookie('openId')
                },{
                    emulateJSON:true
                }).then(function(res){
                    var data = res.data;if(data.code==0){
                        var obj = jQuery.parseJSON(data.data.htmlContract);
                        $('#iframeContract').contents().find('body').html(obj.content);
                        var h = $('#iframeContract').contents().find('html').height();
                        _this.iframeH = h;
                        $('#iframeContract').height(h);
                        this.scrollFn();

                    }else{
                        $.alert(data.message);
                    }
                })
            }
        },
        created:function(){
            this.getFn();
            $('.iframe').height($(window).height()-234);
        }
    })

});


</script>
</html>
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2017-03-16 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档