• 白叔自创放大镜教程


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <script src="jquery-1.7.js" type="text/javascript">
    </script>
    <style type="text/css">
    
    #xiaokuang{position:absolute;
    100px;
    height:100px;
    left:0px;
    top:0px;
    background:rgba(254,238,167,.4);
    display:none;
    }
    
    #datu{
        position:absolute;
        400px;
        height:400px;
        background-color: #999900;
        left:400px;
        top:0px;
        display:none;
        overflow: hidden;
        }
    </style>
    <script>
    $(document).ready(function(){
    $("#xiaotu").mouseover(
                           function(){
                             //  $("#xiaokuang").css('display','block');
                             
                               $("#xiaokuang").show();
                               $("#datu").show();//该方法放到mousemove里会出错,不能不停的show
                           }
    );
    
    
    $("#xiaotu").mouseout(
                           function(){
                             //  $("#xiaokuang").css('display','block');
                             
                               $("#xiaokuang").hide();
                               $("#datu").hide();//该方法放到mousemove里会出错,不能不停的show
                           }
    );
    
    $("#xiaotu").mousemove(
                           function(e){
                               var x=e.clientX-$("#xiaotu").offset().left-$('#xiaokuang').width()/2;
                               var y=e.clientY-$("#xiaotu").offset().top-$('#xiaokuang').height()/2;
                               $("#xiaokuang").css({left:x+'px',top:y+'px'});
                               
                               
                             
                               
                               
                               
                               
                               if(x<0)
                               $("#xiaokuang").css("left","0px");
                               if(x>($('#xiaoimg').width()-$('#xiaokuang').width()))
                               $("#xiaokuang").css("left",$('#xiaoimg').width()-$('#xiaokuang').width()+"px");
                               if(y<0)
                                $("#xiaokuang").css("top","0px");
                                 if(y>($('#xiaoimg').height()-$('#xiaokuang').height()))
                               $("#xiaokuang").css("top",$('#xiaoimg').height()-$('#xiaokuang').height()+"px");
                               //不能直接用div xiaotu 宽度,它没有宽度,调用数值会和屏幕宽度等宽
                               
                                
                                 
                                 
                                 
                                   
                           var newx=x*2;   
                           var newy=y*2;  
                           
                           if(newx<0)newx=0;
                           if(newx>($('#datu img').width()-$('#datu').width()))newx=$('#datu img').width()-$('#datu').width();
                           if(newy<0)newy=0;
                           if(newy>($('#datu img').height()-$('#datu').height()))newy=$('#datu img').height()-$('#datu').height();
                           
                           $('#datu img').css("margin-left",-newx+'px');
                           $('#datu img').css("margin-top",-newy+'px');
                           
                           
                            $("#mydebug").html($('#datu img').width()-$('#datu').width()+"  "+"newx"+newx+"newy"+newy+"e.clientX"+e.clientX+"$('#xiaotu').offset().top"+$("#xiaotu").offset().left+"$('#xiaokuang').width()/2"+$('#xiaokuang').width()/2+"$('#xiaotu').width()"+$('#xiaotu').width());
                           
                           }      
                           );
    
    });
    
    
    
    //实验证明,只写mouseover不写document ready是不能生效的。 .mouseover括号结尾不写分号也是不能生效的
    </script>
    </head>
    
    <body>
    <table width="400" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td height="150">&nbsp;</td>
      </tr>
    </table>
        <div id="xiaotu" style="position:relative"><img src="s2.jpg" width="400" height="250" id="xiaoimg" /><div id="xiaokuang"></div><div id="datu"><img src="s1.jpg" width="800" height="500"  /></div></div>
        <div id="mydebug" style="height:200px; 400px;"></div>
    </body>
    </html>
  • 相关阅读:
    vue项目index.html缓存
    vue刷新当前页面
    keep-alive
    JS刷算法题:二叉树
    CSS动效集锦,视觉魔法的碰撞与融合(三)
    算法:栈和队列题目集合(一)
    浅谈设计模式(二):装饰器模式|中介模式|原型模式
    聊聊JS的二进制家族:Blob、ArrayBuffer和Buffer
    浅谈设计模式(一):状态模式|外观模式|代理模式
    纵论WebAssembly,JS在性能逆境下召唤强援
  • 原文地址:https://www.cnblogs.com/pegasus827/p/10038802.html
Copyright © 2020-2023  润新知