360全景照片展示由于它的真实性、全视角等特点能够很好的展现产品。而我在工作之余写了一个360度图片展示效果,改变了普通图片平淡的特点,让人们在网上能够进行 360 度全视角观察,而且通过交互操作,可以实现自由浏览,从而震撼的视觉效果。
 
全景照片:所谓“全景拍摄”就是将所有拍摄的多张图片拼成一张全景图片。它的基本拍摄原理是搜索两张图片的边缘部分,并将成像效果最为接近的区域加以重合,以完成图片的自动拼接。现在的智能手机也基本带这个功能。

这个小DEMO基于全景照片的左右边缘较为接近且适宜自动拼接与jser熟知的无缝滚动原理。下面这个图片就是本DEMO实现原理的简化图。



HTML结构:
  1. <div class="pop_see_360pic" id="popseebox"> 
  2.         <div class="pic_box"> 
  3.             <div class="loading" id="pic360load">Loading...</div> 
  4.             <div class="pic_box_inner" id="pic_box_inner"> 
  5.                 <img src="" /> 
  6.             </div> 
  7.             <a href="void(0)" class="prev_arrow" id="prev"><span></span></a> 
  8.             <a href="void(0)" class="pause_arrow" id="pause"><span></span></a> 
  9.             <a href="void(0)" class="next_arrow" id="next"><span></span></a> 
  10.         </div> 
  11.         <div class="pic_list"> 
  12.             <ul id="picListItem"> 
  13.                 <li><a href="void(0)" class="sel">Standard Room</a></li> 
  14.                 <li><a href="void(0)">Sea view Room (PVSU1)</a></li> 
  15.                 <li><a href="void(0)">Royale Suite</a></li> 
  16.                 <li><a href="void(0)">Bella Suite</a></li> 
  17.                 <li><a href="void(0)">11Royale Suite (PVSU1)</a></li> 
  18.                 <li><a href="void(0)">Royale Suite</a></li> 
  19.                 <li><a href="void(0)">Bella Suite</a></li> 
  20.                 <li><a href="void(0)">Royale Suite (PVSU1)</a></li> 
  21.             </ul> 
  22.         </div> 
  23.         <a href="void(0)" class="mbtn mbtn-mini" id="close">X</a> 
  24.     </div> 
CSS样式:
  1. *{margin:0padding:0;} 
  2. li{list-stylenone; } 
  3. body{font-size:11px;} 
  4. a{text-decorationnone;} 
  5. .pop_see_360pic:after {clear:both;display:block;content:".";height:0;visibility:hidden;font-size:0;line-height:0;} 
  6. .pop_see_360pic {position:relative;float:left;width:550px;padding:14px 70px 14px 71px;border:1px solid #CECECE;background-color:#FFFFFF;zoom:1;} 
  7. .pop_see_360pic_fla {width:650px;padding:20px 40px 14px 0;} 
  8. .pop_see_360pic .mbtn {position:absolute;top:12px;right:20px;} 
  9. .pop_see_360pic .pic_box {position:relative;float:left;width:320px;height:240px;overflow:hidden;margin-right:10px;} 
  10. .pop_see_360pic .pic_box img {display:block;width:320px;height:240px;} 
  11. .pop_see_360pic .pic_list {float:left;width:220px;height:240px;overflow-x:hidden;overflow-y:auto;} 
  12. .pop_see_360pic .pic_list ul {overflow:hidden;width:218px;border:1px solid #CECECE;border-bottom:0 none;} 
  13. .pop_see_360pic .pic_list li {float:left;width:218px;height:35px;font-weight:bold;border-bottom:1px solid #CECECE;} 
  14. .pop_see_360pic .pic_list li a {display:block;width:100%;height:18px;overflow:hidden;padding:9px 10px 8px 10px;zoom:1;} 
  15. .pop_see_360pic .pic_list li a:hover {text-decoration:none;background-color:#EFF0F1;} 
  16. .pop_see_360pic .pic_list li a.sel, 
  17. .pop_see_360pic .pic_list li a.sel:hover {text-decoration:none;background-color:#C1D3F1;} 
  18. .pop_see_360pic .prev_arrow, 
  19. .pop_see_360pic .pause_arrow, 
  20. .pop_see_360pic .next_arrow {position:absolute;left:124px;bottom:0;width:70px;height:27px;overflow:hidden;padding-top:17px;text-align:center;font-size:12px;filter:progid:DXImageTransform.Microsoft.gradient(enabled='true',startColorstr='#7FFFFFFF', endColorstr='#7FFFFFFF');background:url(about:blank);background:rgba(255,255,255,0.5);z-index:9;} 
  21. :root .pop_see_360pic .prev_arrow, 
  22. :root .pop_see_360pic .pause_arrow, 
  23. :root .pop_see_360pic .next_arrow {filter:none;} 
  24. .pop_see_360pic .prev_arrow {left:53px;border-radius:10px 0 0 0;} 
  25. .pop_see_360pic .next_arrow {left:195px;border-radius:0 10px 0 0;} 
  26. .pop_see_360pic .prev_arrow:hover, 
  27. .pop_see_360pic .pause_arrow:hover, 
  28. .pop_see_360pic .next_arrow:hover {font-size:11px;} 
  29. .pop_see_360pic .pic_box img {widthauto;height240px;} 
  30. .pop_see_360pic{margin:10px;} 
  31. .pop_see_360pic .loading{positionabsolute; top:0; left:0background:#ebebeb url(http://www.daqianduan.com/wp-content/uploads/2012/12/loading_50_g.gif) no-repeat 134px 78pxwidth320pxheight:240pxz-index:998text-indent-999px;} 
  32. .pic_box_inner{position:absolutewidth:5000pxoverflowhidden; *zoom:1;} 
  33. .pic_box_inner img{float:left;} 
javascript:
  1. window.onload = function(){ 
  2. var pic360play = function(){this.initialize()} 
  3.  
  4. pic360play.prototype = { 
  5.     initialize : function(){ 
  6.         var oThis = this
  7.  
  8.         this.popseebox = document.getElementById("popseebox"); 
  9.         this.pic360load = document.getElementById("pic360load"); 
  10.  
  11.         this.oPrev = document.getElementById("prev"); 
  12.         this.opause = document.getElementById("pause"); 
  13.         this.oNext = document.getElementById("next"); 
  14.  
  15.         this.timeout = 0; 
  16.         this.picList = document.getElementById("picListItem"); 
  17.         this.oScrollIner = document.getElementById("pic_box_inner"); 
  18.         this.oScrollBox = this.oScrollIner.parentNode; 
  19.         this.oScrollImg = this.oScrollBox.getElementsByTagName("img")[0]; 
  20.  
  21.         /* ============= copy img for scrool no space =========== */ 
  22.         this.oScrollImgcopy = this.oScrollImg.cloneNode(true); 
  23.         this.oScrollIner.appendChild(this.oScrollImgcopy); 
  24.  
  25.         /* =========== bind close pic360play popup event ========== */ 
  26.         document.getElementById("close").onclick = function(){ 
  27.             oThis.close(popseebox); 
  28.         } 
  29.  
  30.         /* ============== reset first img and layout ===============*/ 
  31.         oThis.resetImg(); 
  32.  
  33.         /* ============== give per link tabs pic =================*/ 
  34.         oThis.picList.onclick = function(e) { 
  35.             e = window.event ? window.event : e; 
  36.             var who = e.target ? e.target : e.srcElement; 
  37.             if(who.nodeType == 1 && who.tagName == "A" && who.getAttribute("imgurl") && oThis.oScrollImgcopy.src != who.getAttribute("imgurl")){ 
  38.                 oThis.pic360load.style.display = "block"
  39.                 var newimg = new Image(); 
  40.                 newimg.src = who.getAttribute("imgurl"); 
  41.                 newimg.onload = function(){ 
  42.                     oThis.oScrollImg.src = oThis.oScrollImgcopy.src = who.getAttribute("imgurl"); 
  43.                         oThis.oScrollImg = oThis.oScrollBox.getElementsByTagName("img")[0]; 
  44.                         oThis.oScrollImgcopy = oThis.oScrollBox.getElementsByTagName("img")[1]; 
  45.                         oThis.pic360load.style.display = "none"
  46.                         clearTimeout(oThis.timeout); 
  47.                         oThis.resetMiddle(); 
  48.                         oThis.timeout = setInterval(function(){ 
  49.                             oThis.prev(oThis); 
  50.                         },16); 
  51.  
  52.                 } 
  53.  
  54.                 return false
  55.             } 
  56.         };   
  57.         /* ============ play pic ============= */  
  58.          this.oPrev.onclick = function(){ 
  59.             clearTimeout(oThis.timeout); 
  60.             oThis.timeout = setInterval(function(){ 
  61.                 oThis.prev(); 
  62.             },16); 
  63.          } 
  64.  
  65.          this.oNext.onclick = function(){ 
  66.             clearTimeout(oThis.timeout); 
  67.             oThis.timeout = setInterval(function(){ 
  68.                 oThis.next(); 
  69.             },16); 
  70.  
  71.          } 
  72.  
  73.          this.opause.onclick = function(){ 
  74.             clearTimeout(oThis.timeout); 
  75.          } 
  76.     }, 
  77.     getStyle : function(elem,name){ 
  78.         if(elem.style[name]){ 
  79.         return elem.style[name]; 
  80.         } 
  81.         else if(elem.currentStyle){ 
  82.             return elem.currentStyle[name]; 
  83.         } 
  84.         else if(document.defaultView && document.defaultView.getComputedStyle){ 
  85.             name = name.replace(/[A-Z]/g,"-$1"); 
  86.             name = name.toLowerCase(); 
  87.             var s = document.defaultView.getComputedStyle(elem,''); 
  88.             return s && s.getPropertyValue(name); 
  89.         } 
  90.         return null
  91.     }, 
  92.     prev : function(){ 
  93.         if(parseFloat(this.oScrollIner.style.left)  parseFloat(this.getStyle(this.oScrollBox,"width")) - this.oScrollImg.width) 
  94.             this.oScrollIner.style.left =  parseFloat(this.oScrollIner.style.left) - this.oScrollImg.width + "px"
  95.          this.oScrollIner.style.left = parseFloat(this.oScrollIner.style.left) + 1 + "px"
  96.     }, 
  97.     close : function(obj){ 
  98.         obj.style.display = "none"
  99.             return false
  100.     }, 
  101.     resetImg : function(){ 
  102.         var picListItemLink = this.picList.getElementsByTagName("a"); 
  103.         var oThis = this
  104.         oThis.oScrollImg.src = oThis.oScrollImgcopy.src = picListItemLink[1].getAttribute("imgurl"); 
  105.         var resetImg = new Image(); 
  106.         resetImg.src= picListItemLink[1].getAttribute("imgurl"); 
  107.  
  108.         resetImg.onload = function(){ 
  109.             //reset img location middle 
  110.             oThis.resetMiddle(); 
  111.  
  112.             oThis.pic360load.style.display = "none"
  113.  
  114.             oThis.timeout = setInterval(function(){ 
  115.                 oThis.prev(oThis); 
  116.             },16); 
  117.         } 
  118.     }, 
  119.     resetMiddle: function(){ 
  120.         this.oScrollIner.style.left = - (this.oScrollImg.width/2 - parseFloat(this.getStyle(this.oScrollBox,"width"))/2) + "px";             
  121.     } 
  122.  
  123. new pic360play(); 
  124.  

返回顶部