zoukankan      html  css  js  c++  java
  • 移动端-图片可手滑放大缩小、删除功能

    1. html文件加入:

    <script src="../js/pinchzoom.js"></script>
     
    <div id="buiPhoto" class="bui-upload bui-fluid-space-4">
                                <div class="span1">
                                    <div id="btnUpload" class="bui-btn">          //上传图片处
                                        <i class="icon-plus large"></i>
                                    </div>
                                </div>
    </div>

    <main id="beingTest_list">         //图片放大的模板
                    <div class="zezhao">
                        <div class="colse">关闭</div>
                        <div class="showImg">
                        </div>
                    </div>
     </main>
     
    2. js文件 示例  渲染模板为: 
    const _PictrueView = function(res){
            let $facePhoto = $("#buiPhoto");
            let $uploadBtn = $("#btnUpload").parent();
            let currentIndex = 0,currentName = "";
            let Data=res.questions[_pro].answer;
            console.log('banging',res)
        
            for(let i=0;i<Data.length;i++){
                let uri = common.settings.downloadAttachmentUrl+"?attachID="+Data[i].attachmentId;
                console.log("====================="+uri)
                currentIndex = i
                currentName = Data[i].name 
                $uploadBtn.before(templatePhoto(uri))    //增加图片dom
               
            }
    function templatePhoto(url) {
                return `<div class="span1" data-index="${currentIndex}" data-name="${currentName}">
                        <div class="bui-upload-thumbnail"><img class="imgClass" src="${url}" alt="" /><i class="icon-removefill"></i></div>
                    </div>`
            }
    //点击查看可放大缩小图片
                $(".imgClass").each(function(){
                    $(this).on('click',function(){
                    console.log('this.src',$(this).attr("src"));
                    $(".zezhao").show();  
                    var html = `<img src="${$(this).attr("src")}">`
                    $(".showImg").append(html);
                    $(".showImg>img").each(function(i) {       //循环遍历showimg下的img
                        new RTP.PinchZoom($(this), {});      //手指滑动可放大缩小图片
                    });
                    $(".colse").click(function(){
                        $(this).parent().hide();
                        $('.showImg>div.pinch-zoom-container').remove();
                    })

                    })
                })
    //删除相应图片
                $facePhoto.on("click", ".icon-removefill", function(e) {
                    let $item = $(this).parent().parent();
                    let index = $item.attr("data-index");
                    // 删除对应的上传数据
                    uiUpload.remove(index);
                    // 删除dom显示  uiUpload是用了bui.upload();
                    $item.remove();
                    e.stopPropagation();
                    attachment = resdata.questions[_pro].answer;
                    attachment.splice(index,1);
                    if(attachment.length < 9){
                        $("#btnUpload").show();
                        if(attachment.length < 1){
                            $(".qIndex").eq(resdata.questions[_pro].orderNo - 1).css({ "background": "white", "color": "rgb(111,135,179)", "border": "1px solid rgb(111,135,179)" });
                        }
                    }
                })
    }

     

  • 相关阅读:
    bzoj4758: [Usaco2017 Jan]Subsequence Reversal(区间dp)
    bzoj4580: [Usaco2016 Open]248(区间dp)
    1617: [Usaco2008 Mar]River Crossing渡河问题(dp)
    bzoj21012101: [Usaco2010 Dec]Treasure Chest 藏宝箱(滚动数组优化dp)
    P2339 提交作业usaco(区间dp)
    day11
    bzoj2330: [SCOI2011]糖果(差分约束)
    P2921 [USACO08DEC]在农场万圣节Trick or Treat on the Farm(Tarjan+记忆化)
    P2700逐个击破(并查集/树形dp)
    bzoj1770: [Usaco2009 Nov]lights 燈(折半搜索)
  • 原文地址:https://www.cnblogs.com/chchchc/p/11938910.html
Copyright © 2011-2022 走看看