html 配合js实现文本点击复制,图片点击放大

 


<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

    <meta name="viewport" content="initial-scale=1.0,user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>流量、话费充值</title>
    <link rel="stylesheet" id="wp-block-library-css" href="static/style.min.css" type="text/css" media="all">
    <link rel="stylesheet" id="style-css" href="static/main.css" type="text/css" media="all">
    <link rel="stylesheet" href="static/font-awesome.min.css" type="text/css" media="all">
    <script type="text/javascript" src="static/jquery.js"></script>
    <link rel="canonical" href="">
    <style type="text/css">
        .logo a:before {
            opacity: 1
        }

        html {
            padding: 1px;
        }

    </style>
</head>

<body class="" id="body-header-top">

<h2 class="btt mobies">
    <i class="fa fa-gittip" style="color: #E53A40;"></i>充值号码
    <span onclick="copyContent(this);"><b>12345679321563665</b></span>
</h2>

<div class="update_area">
    <p><br></p>
    <div class="update_area_content" style="text-align: center;margin-top: 10px;">
        <img src="1.jpg" class="pic" style="height: 130px;height: 130px;">
        <img src="2.jpg" class="pic" style="height: 130px;height: 130px;">
    </div>
    <p><br></p>
    <div style="padding: 5px;">
        <span style="color: red;">提示:支付时请备注上充值号</span>

        <input id="copy_content" type="text" value=""
               style="position: absolute;top: 0;left: 0;opacity: 0;z-index: -10;"/>
    </div>
    <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;">
        <div id="innerdiv" style="position:absolute;">
            <img id="bigimg" style="border:5px solid #fff;" src=""/>
        </div>
    </div>

    <div style="padding: 5px;margin-top: 10px;">
        <p>充值步骤如下:</p>
        <p>1、点击充值号复制</p>
        <p>2、在此页面更具充值面额点击对应二维码</p>
        <p>3、识别或者扫马备进如付款支付界面</p>
        <p>4、备注上你的设备编号或者号码进行付款</p>
        <p>5、付款成功后这边会为你进行代理充</p>
        <p><br></p>
        <p>注:</p>
        <p>1、如果你忘记备注或者有误请扫码添加客服;</p>
        <p>2、你也可以直接添加客服为你进行代理充值</p>
        <p><br></p>
        <p>客服二维码:</p>
    </div>
    <div class="update_area_content" style="text-align: center;margin-top: 10px;">
        <img src="k1.jpg" class="pic" style="height: 130px;height: 130px;">
        <img src="k2.jpg" class="pic" style="height: 130px;height: 130px;">
    </div>
</div>
<br/>

</body>
</html>

<script type="text/javascript" src="static/script.js"></script>

<script language="JavaScript">
    $(function () {
        $(document).on('click', '.pic', function () {
            var _this = $(this);//将当前的pimg元素作为_this传入函数
            imgShow("#outerdiv", "#innerdiv", "#bigimg", _this);
        });
    });

    function copyContent(ElementObj) {
        //获取点击的值
        var clickContent = ElementObj.innerText;
        $('#copy_content').val(clickContent);
        var inputElement = document.getElementById("copy_content").select();
        document.execCommand("Copy");
        alert('已复制', 1000);
    }

    function imgShow(outerdiv, innerdiv, bigimg, _this) {
        var src = _this.attr("src");//获取当前点击的pimg元素中的src属性
        $(bigimg).attr("src", src);//设置#bigimg元素的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.8;//缩放尺寸,当图片真实宽度和高度大于窗口宽度和高度时进行缩放

            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;//计算图片与窗口左边距
            var h = (windowH - imgHeight) / 2;//计算图片与窗口上边距
            $(innerdiv).css({"top": h, "left": w});//设置#innerdiv的top和left属性
            $(outerdiv).fadeIn("fast");//淡入显示#outerdiv及.pimg
        });

        $(outerdiv).click(function () {//再次点击淡出消失弹出层
            $(this).fadeOut("fast");
        });
    }
</script>

具体的实现方式代码是是在参考网络上几篇博客,然后整合到自己html5项目中

参考网址:

https://www.cnblogs.com/yunshangwuyou/p/10538504.html

https://www.cnblogs.com/wisewrong/p/7473978.html

 

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值