JS历理 foot.js的部分功能

document.writeln("<div id=\'outerdiv\' style=\'position:fixed;top:0;left:0;background:rgba(0,0,0,0.7);z-index:2;width:100%;height:100%;display:none;\'>");
document.writeln("<div id=\'innerdiv\' style=\'position:absolute;\'>");
document.writeln("<img id=\'bigimg\' style=\'border:5px solid #fff;\' src=\'\' /></div></div>");
$(function(){
    //图片放大的方法
    $(".pimg").click(function(){
        var _this = $(this);
        imgShow("#outerdiv", "#innerdiv", "#bigimg", _this);
    });

    //列表的展开与收缩的方法
    $('#show').click(function() {
        $('.ui-content').addClass('layui-show');
    });
    $('#toggle').click(function() {
        $('.ui-content').toggleClass('layui-show');
    });

    //多行文本域的高度为其内容的高度
    $.fn.autoHeight = function(){
        function autoHeight(elem){
            elem.style.height = 'auto';
            elem.scrollTop = 0;
            elem.style.height = elem.scrollHeight + 'px';
        }
        this.each(function(){
            autoHeight(this);
            $(this).on('keyup', function(){
                autoHeight(this);
            });
        });
    }
    $('textarea[autoHeight]').autoHeight();
});

//图片放大的方法
function imgShow(outerdiv, innerdiv, bigimg, _this){
    var src = _this.attr("src");
    $(bigimg).attr("src", src);
    $("<img/>").attr("src", src).load(function(){
        var windowW = $(window).width();
        var windowH = $(window).height();
        var realWidth = this.width;
        var realHeight = this.height;
        var imgWidth, imgHeight;
        var scale = 0.9;
        if(realHeight>windowH*scale) {
            imgHeight = windowH*scale;
            imgWidth = imgHeight/realHeight*realWidth;
            if(imgWidth>windowW*scale) {
                imgWidth = windowW*scale;
            }
        } else if(realWidth>windowW*scale) {
            imgWidth = windowW*scale;
            imgHeight = imgWidth/realWidth*realHeight;
        } else {
            imgWidth = realWidth;
            imgHeight = realHeight;
        }
        $(bigimg).css("width",imgWidth);
        var w = (windowW-imgWidth)/2-5;
        var h = (windowH-imgHeight)/2-5;
        $(innerdiv).css({"top":h, "left":w});
        $(outerdiv).fadeIn("fast");
    });

    $(outerdiv).click(function(){
        $(this).fadeOut("fast");
    });
}

//删除数据的方法
function confirmDel(v,n){
    var url = window.location.href;
    var path = encodeURIComponent(url); //URL需要编码传输
    var value = window.atob(decodeURIComponent(v));
    var name = window.atob(decodeURIComponent(n));
    layer.confirm('你确定要删除'+name+'-'+value+'的这条信息吗', {
        btn: ['确定','取消']
    }, function(){
        location.href="/Z/ZZZ/delete.php?f="+v+"&t="+n+"&p="+path;
    }, function(){
        layer.msg('已取消操作!');
    });
}
posted @ 2024-08-06 20:05  onestopweb  阅读(8)  评论(0)    收藏  举报