• 鼠标经过显示大图


    需求是这样的,页面中的图片不能显示原图大小,那样布局会乱掉,所以需要显示小图,然后当鼠标经过的时候显示大图即可。

    <div id="Photo" style="overflow:hidden;text-align:center;padding:10px">
                
    </div>
    <div id="enlarge_images"></div>

    页面代码就是这个就够了,当然了,由于我的图片是后台请求后加载进来的,所以图片暂时是空的。

                    var Photo = document.getElementById("Photo");
                    var gg = Photo.getElementsByTagName("img");
                    var ei = document.getElementById("enlarge_images");
                    for (i = 0; i < gg.length; i++) {
                        var ts = gg[i];
                        ts.onmousemove = function (event) {
                            event = event || window.event;
                            ei.style.display = "block";
                            ei.innerHTML = '<img src="' + this.src + '" />';
                            ei.style.top = 60 + "px";
                            ei.style.left = document.body.scrollLeft + event.clientX + 10 + "px";
                        }
                        ts.onmouseout = function () {
                            ei.innerHTML = "";
                            ei.style.display = "none";
                        }
                        ts.onclick = function () {
                            window.open(this.src);
                        }
                    }

    这个比较简单,就是在鼠标经过img标签的时候,打开显示大图的弹窗而已。

    <!DOCTYPE html>
    <html>
    
    <head>
        <meta charset="UTF-8">
        <title></title>
        <style>
        #demo {
            overflow: hidden;
             120px;
            text-align: center;
            padding: 10px;
        }
    
        #demo img {
            border: none;
             100px;
            height: 100px;
            border: 5px solid #f4f4f4
        }
    
        #enlarge_images {
            position: absolute;
            display: none;
            z-index: 2;
            border: 5px solid #f4f4f4
        }
        </style>
    </head>
    
    <body>
        <div id="demo" style="overflow:hidden;120px;text-align:center;padding:10px">
            <img src="aaa.jpg"><img src="aaa.jpg"><img src="aaa.jpg">
        </div>
        <div id="enlarge_images"></div>
        <script>
        var demo = document.getElementById("demo");
        var gg = demo.getElementsByTagName("img");
        var ei = document.getElementById("enlarge_images");
        for (i = 0; i < gg.length; i++) {
            var ts = gg[i];
            ts.onmousemove = function(event) {
                event = event || window.event;
                ei.style.display = "block";
                ei.innerHTML = '<img src="' + this.src + '" />';
                ei.style.top = document.body.scrollTop + event.clientY + 10 + "px";
                ei.style.left = document.body.scrollLeft + event.clientX + 10 + "px";
            }
            ts.onmouseout = function() {
                ei.innerHTML = "";
                ei.style.display = "none";
            }
            ts.onclick = function() {
                window.open(this.src);
            }
        }
        </script>
    </body>
    
    </html>
    完整代码
  • 相关阅读:
    python-学习 补充模块;面向对象程序设计
    python学习- 常用模块与re正则
    python-学习 协程函数 模块与包
    python-学习 初级atm小脚本、函数嵌套、装饰器、生成器、迭代器、三元表达式
    模拟登陆古诗文网
    正则表达式(括号)、[中括号]、{大括号}的区别
    MongoDB的基本操作
    语音合成以及语音识别
    flask中的CBV,flash,Flask-Session,WTForms
    Flask基础2 蓝图,实例化配置,app对象配置,特殊装饰器
  • 原文地址:https://www.cnblogs.com/Rexcnblog/p/8980425.html
Copyright © 2020-2023  润新知