js點擊圖片查看大圖,並可以拖動,且滾動滑輪放大縮小

來源:互聯網
上載者:User

標籤:

JQuery

function hideMax(){    $(".MAX_div").remove();    $("#Cover_Div").hide(); }    function showMax(url){        $("#Cover_Div").show();        var Image=function(){            return document.createElement("img");        }          var DIV=function(){            return document.createElement("div");        }                  var div=new DIV();            var close_div=new DIV();        var close_img=new Image();            var img=new Image();        var _enter=false;            $(".MAX_div").remove();            div.setAttribute("class","MAX_div");            close_div.setAttribute("class","close");            close_div.setAttribute("title","點擊關閉");                                     img.setAttribute("class","showMax");            img.src=url;            close_img.src="tpl/images/delete.png";            img.onmouseover=function(){                _enter=true;            }            img.onmouseout=function(){                _enter=false;            }            close_div.onclick=function(){                hideMax();            }            close_div.appendChild(close_img);            div.appendChild(img);            div.appendChild(close_div);            document.body.appendChild(div);                        //var _z=9999;            var close=$(".close");            $(document).ready(function(){             var _move=false;//移動標記             var _x,_y;//滑鼠離控制項左上方的相對位置             var wd;//視窗                $(".showMax").click(function(){                    //alert("click");//點擊(鬆開後觸發)                 //this.style.cursor = "default";//滑鼠形狀                 //this.style.zIndex = 999;                    }).mousedown(function(e){                    _move=true;                    wd=$(this);                                        //this.style.cursor = "move";//滑鼠形狀                   // this.style.zIndex = _z;//視窗層次                   // _z++;                    _x=e.pageX-(isNaN(parseInt(wd.css("left")))?0:parseInt(wd.css("left")));                    _y=e.pageY-(isNaN(parseInt(wd.css("top")))?0:parseInt(wd.css("top")));                           c_x=e.pageX-(isNaN(parseInt(close.css("left")))?0:parseInt(close.css("left")));                    c_y=e.pageY-(isNaN(parseInt(close.css("top")))?0:parseInt(close.css("top")));                                         /*  wd.fadeTo(20, 0.25); *///點擊後開始拖動並透明顯示                    $(document).mousemove(function(e){                        if(_move){                            var x=e.pageX-_x;//移動時根據滑鼠位置計算控制項左上方的絕對位置                            var y=e.pageY-_y;                            var closeX=e.pageX-c_x;                            var closeY=e.pageY-c_y;                            wd.css({top:y,left:x});//控制項新位置                            close.css({top:closeY,left:closeX});                        }                    }).mouseup(function(){                    _move=false;                    /* wd.fadeTo("fast", 1); *///鬆開滑鼠後停止移動並恢複成不透明                  });                });                            });                       //$(".showMax").mouseover(function(){                                var scrollTop = $(window).scrollTop();                var initTop=scrollTop;                var screenheight = window.screen.availHeight; //擷取螢幕高                   $(window).scroll( function() {                     scrollTop = $(window).scrollTop();;                    var w=parseInt($(".showMax").css("width"));                    var h=parseInt($(".showMax").css("height"));                                            if(scrollTop > initTop&&_enter){                            $(".showMax").css({"width":w+Number(28)+"px","height":h+Number(50)+"px"});                            close.css("margin-left",(w-125)<125?125:(w-125)+"px");                            $(window).scrollTop(initTop);//保持捲軸距離底部0px                         }                         if(scrollTop <initTop&&_enter){                            $(".showMax").css({"width":(w-28)<280?280:(w-28)+"px","height":(h-50)<500?500:(h-50)+"px"});                            close.css("margin-left",(w-155-28)<125?125:(w-155-28)+"px");                            $(window).scrollTop(initTop);//保持捲軸距離底部0px                         }                                        //initTop=scrollTop;                   });            //})                                                            function imgdragstart(){return false;}              for(i in document.images)document.images[i].ondragstart=imgdragstart;         }     

CSS

.showMax{    padding:5px;    padding-top:30px;    border-radius:3px;    position:fixed;    z-index:999991;    top:25%;    width:280px;    height:500px;    left:50%;    margin-left:-140px;    background-color:orange;    cursor:move;    }.MAX_div{}.close{   color:#ffffff;   position:fixed;   z-index:999992;   width:14px;   height:14px;   top:25%;   left:50%;   margin-left:125px;   margin-top:8px;}li >img:hover{    border:1px solid orange;    cursor:crosshair;}#Cover_Div{    position: fixed;    z-index: 9999;     width: 100%;    height: 100%;     left: 0;     top: 0;    min-width: 700px;    min-height: 740px;          opacity: 0.5;     filter: alpha(opacity = 50);     background-color: #ffffff; }.cut{    font-weight:bold;    font-weight:normal\0;    font-size:18px;    height:30px;    max-height:35px;    color:#FFFFFF;    font-family:楷書;}

Html

<img  onclick="showMax(‘url")"  src="url" style="width:288px;height:216px;" />

 

js點擊圖片查看大圖,並可以拖動,且滾動滑輪放大縮小

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.