zoukankan      html  css  js  c++  java
  • 360度全景图片

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title></title>
    <style>
    #imgBox{

    height: 378px;
    640px;
    position: relative;
    margin:100px auto;

    }
    #imgBox img{

    position: absolute;

    }
    </style>

    </head>
    <body>

    <div id="imgBox"><img src="img/miaov (0).jpg" height="378" width="640" id="img1" ></div>
    <script>
    var imgBox=document.getElementById("imgBox");

    //预加载 防止卡顿
    for(var i=1;i<77;i++){

    (function(oImg){

    var img=new Image();

    img.onload=function(){

    oImg.src=this.src;

    }


    img.src="img/miaov ("+i+").jpg";
    oImg.style.display="none";
    imgBox.appendChild(oImg);

    })(document.createElement("img"))

    }

    var allImgs=document.getElementsByTagName("img");//所有图片元素
    var lastImg=document.getElementById("img1");//上一张图片元素

    var speed=0; //当抬起鼠标那一刻的速度
    var lastPos=0;//上一次鼠标move的位置
    var x=0; // 记录鼠标move的位置

    var timer=null;//定时器

    document.onmousedown=function(event){

    clearInterval(timer);
    var ev=event || window.event;

    disX=ev.clientX-x; //鼠标按下的位置

    document.onmousemove=function(event){

    var ev=event || window.event;

    x=ev.clientX-disX;

    move();
    speed=x-lastPos;//此时的速度 根据你鼠标移动的快慢不同 大小不同
    lastPos=x;

    return false; //为了拖动的时候防止选中图片


    }


    document.onmouseup=function(){

    document.onmousemove=null;
    document.onmouseup=null;



    timer=setInterval(function(){

    x+=speed;
    move();

    }, 1000/60)

    }

    return false; //为了拖动的时候防止选中图片
    }

     

    function move(){

    speed>0?speed--:speed++;
    if(speed==0){

    clearInterval(timer);
    }
    var l=parseInt(x/10);

    if(l>0){

    l=l%77;

    }

    else{

    l=l+-Math.floor(l/77)*77;

    }


    if(allImgs[l]!=lastImg){

    lastImg.style.display="none";
    allImgs[l].style.display="block";
    lastImg=allImgs[l];


    }

    }

    </script>
    </body>
    </html>

  • 相关阅读:
    51-maven私有库神坑之:“Downloading: http://repo.maven.apache.org/maven2/”
    50-maven 仓库配置
    49-2017年第八届蓝桥杯国赛试题及详解(Java本科B组)
    21-matlab 迷宫题
    20-matlab全排列-函数调用
    52-python 画图二维
    51-python3 pandas读写excel
    48-设置tomcat虚拟路径的两种方法(Eclipse、tomcat、IDEA)
    19-matlab知识点复习二
    【剑指offer】二叉搜索树的后序遍历序列
  • 原文地址:https://www.cnblogs.com/liveoutfun/p/9655197.html
Copyright © 2011-2022 走看看