全景拍摄:所谓“全景拍摄”就是将所有拍摄的多张图片拼成一张全景图片。它的基本拍摄原理是搜索两张图片的边缘部分,并将成像效果最为接近的区域加以重合,以完成图片的自动拼接。现在的智能手机也基本带这个功能。

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

HTML代码

    <div class="pop_see_360pic" style="" id="popseebox">
<div class="pic_box">
<div class="loading" id="pic360load">Loading...</div>
<div class="pic_box_inner" id="pic_box_inner">
<img src="">
</div>
<a href="javascript:void(0)" class="prev_arrow" id="prev"><span>←</span></a> <a href="javascript:void(0)" class="pause_arrow" id="pause"><span>‖</span></a> <a href="javascript:void(0)" class="next_arrow" id="next"><span>→</span></a>
</div>
<div class="pic_list">
<ul id="picListItem">
<li><a href="javascript:void(0)" class="sel">Standard Room</a></li>
<li><a href="javascript:void(0)" imgurl="http://ued.ctrip.com/blog/wp-content/uploads/2012/12/hotel_1.jpg">Sea view Room (PVSU1)</a></li>
<li><a href="javascript:void(0)" imgurl="http://ued.ctrip.com/blog/wp-content/uploads/2012/12/hotel_2.jpg">Royale Suite</a></li>
<li><a href="javascript:void(0)" imgurl="http://ued.ctrip.com/blog/wp-content/uploads/2012/12/hotel_3.jpg">Bella Suite</a></li>
<li><a href="javascript:void(0)" imgurl="http://ued.ctrip.com/blog/wp-content/uploads/2012/12/hotel_4.jpg">11Royale Suite (PVSU1)</a></li>
<li><a href="javascript:void(0)" imgurl="http://ued.ctrip.com/blog/wp-content/uploads/2012/12/hotel_5.jpg">Royale Suite</a></li>
<li><a href="javascript:void(0)" imgurl="http://ued.ctrip.com/blog/wp-content/uploads/2012/12/hotel_6.jpg">Bella Suite</a></li>
<li><a href="javascript:void(0)" imgurl="http://ued.ctrip.com/blog/wp-content/uploads/2012/12/hotel_7.jpg">Royale Suite (PVSU1)</a></li>
</ul>
</div>
<a href="javascript:void(0)" class="mbtn mbtn-mini" id="close">X</a>
</div> 

CSS代码:

*{margin:; padding:;}
li{list-style: none; }
body{font-size:11px;}
a{text-decoration: none;}
.pop_see_360pic:after {clear:both;display:block;content:".";height:;visibility:hidden;font-size:;line-height:;}
.pop_see_360pic {position:relative;float:left;width:550px;padding:14px 70px 14px 71px;border:1px solid #CECECE;background-color:#FFFFFF;zoom:;}
.pop_see_360pic_fla {width:650px;padding:20px 40px 14px 0;}
.pop_see_360pic .mbtn {position:absolute;top:12px;right:20px;}
.pop_see_360pic .pic_box {position:relative;float:left;width:320px;height:240px;overflow:hidden;margin-right:10px;}
.pop_see_360pic .pic_box img {display:block;width:320px;height:240px;}
.pop_see_360pic .pic_list {float:left;width:220px;height:240px;overflow-x:hidden;overflow-y:auto;}
.pop_see_360pic .pic_list ul {overflow:hidden;width:218px;border:1px solid #CECECE;border-bottom:0 none;}
.pop_see_360pic .pic_list li {float:left;width:218px;height:35px;font-weight:bold;border-bottom:1px solid #CECECE;}
.pop_see_360pic .pic_list li a {display:block;width:100%;height:18px;overflow:hidden;padding:9px 10px 8px 10px;zoom:;}
.pop_see_360pic .pic_list li a:hover {text-decoration:none;background-color:#EFF0F1;}
.pop_see_360pic .pic_list li a.sel,
.pop_see_360pic .pic_list li a.sel:hover {text-decoration:none;background-color:#C1D3F1;}
.pop_see_360pic .prev_arrow,
.pop_see_360pic .pause_arrow,
.pop_see_360pic .next_arrow {position:absolute;left:124px;bottom:;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:;}
:root .pop_see_360pic .prev_arrow,
:root .pop_see_360pic .pause_arrow,
:root .pop_see_360pic .next_arrow {filter:none;}
.pop_see_360pic .prev_arrow {left:53px;border-radius:10px 0 0 0;}
.pop_see_360pic .next_arrow {left:195px;border-radius:0 10px 0 0;}
.pop_see_360pic .prev_arrow:hover,
.pop_see_360pic .pause_arrow:hover,
.pop_see_360pic .next_arrow:hover {font-size:11px;}
.pop_see_360pic .pic_box img {width: auto;height: 240px;}
.pop_see_360pic{margin:10px;}
.pop_see_360pic .loading{position: absolute; top:; left:; background:#ebebeb url(http://www.cocss.com/wp-content/uploads/2012/12/loading_50_g.gif) no-repeat 134px 78px; width: 320px; height:240px; z-index:; text-indent: -999px;}
.pic_box_inner{position:absolute; width:5000px; overflow: hidden; *zoom:;}
.pic_box_inner img{float:left;}

JavaScript代码:

var pic360play = function(){this.initialize()}

pic360play.prototype = {
initialize : function(){
var oThis = this; this.popseebox = document.getElementById("popseebox");
this.pic360load = document.getElementById("pic360load"); this.oPrev = document.getElementById("prev");
this.opause = document.getElementById("pause");
this.oNext = document.getElementById("next"); this.timeout = 0;
this.picList = document.getElementById("picListItem");
this.oScrollIner = document.getElementById("pic_box_inner");
this.oScrollBox = this.oScrollIner.parentNode;
this.oScrollImg = this.oScrollBox.getElementsByTagName("img")[0]; /* ============= copy img for scrool no space =========== */
this.oScrollImgcopy = this.oScrollImg.cloneNode(true);
this.oScrollIner.appendChild(this.oScrollImgcopy); /* =========== bind close pic360play popup event ========== */
document.getElementById("close").onclick = function(){
oThis.close(popseebox);
} /* ============== reset first img and layout ===============*/
oThis.resetImg(); /* ============== give per link tabs pic =================*/
oThis.picList.onclick = function(e) {
e = window.event ? window.event : e;
var who = e.target ? e.target : e.srcElement;
if(who.nodeType == 1 && who.tagName == "A" && who.getAttribute("imgurl") && oThis.oScrollImgcopy.src != who.getAttribute("imgurl")){
oThis.pic360load.style.display = "block";
var newimg = new Image();
newimg.src = who.getAttribute("imgurl");
newimg.onload = function(){
oThis.oScrollImg.src = oThis.oScrollImgcopy.src = who.getAttribute("imgurl");
oThis.oScrollImg = oThis.oScrollBox.getElementsByTagName("img")[0];
oThis.oScrollImgcopy = oThis.oScrollBox.getElementsByTagName("img")[1];
oThis.pic360load.style.display = "none";
clearTimeout(oThis.timeout);
oThis.resetMiddle();
oThis.timeout = setInterval(function(){
oThis.prev(oThis);
},16); } return false;
}
};
/* ============ play pic ============= */
this.oPrev.onclick = function(){
clearTimeout(oThis.timeout);
oThis.timeout = setInterval(function(){
oThis.prev();
},16);
} this.oNext.onclick = function(){
clearTimeout(oThis.timeout);
oThis.timeout = setInterval(function(){
oThis.next();
},16); } this.opause.onclick = function(){
clearTimeout(oThis.timeout);
}
},
getStyle : function(elem,name){
if(elem.style[name]){
return elem.style[name];
}
else if(elem.currentStyle){
return elem.currentStyle[name];
}
else if(document.defaultView && document.defaultView.getComputedStyle){
name = name.replace(/[A-Z]/g,"-$1");
name = name.toLowerCase();
var s = document.defaultView.getComputedStyle(elem,'');
return s && s.getPropertyValue(name);
}
return null;
},
prev : function(){
if(parseFloat(this.oScrollIner.style.left) < -(this.oScrollImg.width + parseFloat(this.getStyle(this.oScrollBox,"width"))) ){
this.oScrollIner.style.left = parseFloat(this.oScrollIner.style.left) + this.oScrollImg.width + "px";
}
this.oScrollIner.style.left = parseFloat(this.oScrollIner.style.left) - 1 + "px"; },
opause : function(){
clearTimeout(this.timeout);
},
next : function(){
if(parseFloat(this.oScrollIner.style.left) > parseFloat(this.getStyle(this.oScrollBox,"width")) - this.oScrollImg.width)
this.oScrollIner.style.left = parseFloat(this.oScrollIner.style.left) - this.oScrollImg.width + "px";
this.oScrollIner.style.left = parseFloat(this.oScrollIner.style.left) + 1 + "px";
},
close : function(obj){
obj.style.display = "none";
return false;
},
resetImg : function(){
var picListItemLink = this.picList.getElementsByTagName("a");
var oThis = this;
oThis.oScrollImg.src = oThis.oScrollImgcopy.src = picListItemLink[1].getAttribute("imgurl");
var resetImg = new Image();
resetImg.src= picListItemLink[1].getAttribute("imgurl"); resetImg.onload = function(){
//reset img location middle
oThis.resetMiddle(); oThis.pic360load.style.display = "none"; oThis.timeout = setInterval(function(){
oThis.prev(oThis);
},16);
}
},
resetMiddle: function(){
this.oScrollIner.style.left = - (this.oScrollImg.width/2 - parseFloat(this.getStyle(this.oScrollBox,"width"))/2) + "px";
}
} new pic360play();

转自:携程设计委员会

JavaScript实现360度全景图片展示效果的更多相关文章

  1. jQuery Panorama Viewer – 360度全景展示插件

    jQuery Panorama Viewer 这款插件可以帮助你在网站中嵌入全景图片.要做到这一点,首先只需要在页面中引入最新的 jQuery 库,以及 jquery.panorama_viewer. ...

  2. 使用Javascript来创建一个响应式的超酷360度全景图片查看幻灯效果

    360度的全景图片效果常常可以用到给客户做产品展示,今天这里我们推荐一个非常不错的来自Robert Pataki的360全景幻灯实现教程,这里教程中将使用javascript来打造一个超酷的全景幻灯实 ...

  3. 使用 ThreeSixty 创建可拖动的 360 度全景图片预览效果

    ThreeSixty 是生成可拖动的360度预览图像序列的 jQuery 插件.只需要在你的 HTML 页面包引入最新的 jQuery 和 threesixty.js 文件就可以使用了,支持键盘上的箭 ...

  4. 原生Js封装的产品图片360度展示

    挺简单的一段程序,但是效果不错: 1.把需要展示的36张图片先预加载到浏览器缓存里 2.给展示图片的div添加方法 3.通过鼠标左右移动的像素转换图片 在线效果预览:http://jsfiddle.n ...

  5. threesixty.min.js 和jquery.threesixty.js使用总结----实现360度展示

    最近公司做一个项目需要360度展示汽车的外观,就用到了threesixty.min.js,自己总结一下使用方法: treesixty.min.js 源码: /*! threesixty-slider ...

  6. 《JavaScript 实战》:实现图片幻滑动展示效果

    滑动展示效果主要用在图片或信息的滑动展示,也可以设置一下做成简单的口风琴(Accordion)效果.这个其实就是以前写的图片滑动展示效果的改进版,那是我第一篇比较受关注的文章,是时候整理一下了. 有如 ...

  7. 利用Canvas实现360度浏览

    前言:最近几个月来到新公司,主要从事移动端方面的开发,有时候也挺忙挺累的,于是就好一段时间没写博客了.其实自己在这几个月里,自己对canvas以及createjs和egret都有了一定程度上的认识与掌 ...

  8. html5人物图片360度立体旋转

    体验效果:http://hovertree.com/texiao/html5/10.htm 下载:http://hovertree.com/hvtart/bjae/t16oddyt.htm 代码如下: ...

  9. 360度3D 旋转插件

    Circlr插件是一款基于jQuery的可以对图片进行360度全方位旋转展示的插件.Circlr通过按一定角度规律拍摄的产品图片,制作出可以使用鼠标拖动.鼠标滚轮和移动触摸来进行图片逐帧旋转的效果.比 ...

随机推荐

  1. bootstrap + angularjs + seajs构建Web Form前端2

    bootstrap + angularjs + seajs构建Web Form前端(二) 回顾 上一篇讲解了引入bootstrap构建一个简单的登录页面,如何让angularjs自动启动并绑定视图,操 ...

  2. 对student进行增删改

    drop package TechEd_pkg_Student; CREATE OR REPLACE PACKAGE TechEd_pkg_Student AS FUNCTION F_CREATE(p ...

  3. Winform 程序嵌入WPF程序 并发送消息

    废话不多说,先看解决方案目录 WindowsFormsDemo是主程序,WpfApp是嵌入的WPF程序,先看WPF程序,程序默认启动的页面是MainWindow.xaml,这里注释掉App.xaml里 ...

  4. [转]Hooked on DTrace

    source link: 1.http://blog.bignerdranch.com/1907-hooked-on-dtrace-part-1/ 2.http://blog.bignerdranch ...

  5. JS OffsetParent属性

       offsetParent 属性返回一个对象的引用,这个对象是距离调用offsetParent的元素最近的(在包含层次中最靠近的),并且是已进行过CSS定位的容器元素. 如果这个容器元素未进行CS ...

  6. C#HTTP代理的实现之注册表实现

    HTTP代理的实现形式,可以通过修改注册表项,然后启动浏览器来实现,也可以通过SOCKET通信,构造HTTP头实现.下面是关于注册表实现的方式. 注册表实现,只需要修改几个关键的注册表项就可以了. 第 ...

  7. .net下将富文本编辑器文本原样读入word文档

    关键词:富文本编辑器  生成word  样式 为了解决标题中提出的问题,首选需要了解,在.net环境下读取数据库中的内容动态生成word至少有2种方式,[方式一]一种方式是在项目中添加引用,例如在“添 ...

  8. 相对于C#,PHP中的个性化语法

    相对于C#,PHP中的个性化语法 背景 今天把PHP的基本语法结构熟悉了一下,包括:变量.类型.常量.运算符.字符串.作用域和函数等,本文列举一些我需要强化记忆的结构(和C#不同). 一些个性化的结构 ...

  9. linux学习之linux的hostname修改详解《转》

    linux的hostname是一个kernel变量,可以通过hostname命令来查看本机的hostname.也可以直接cat /proc/sys/kernel/hostname查看. #hostna ...

  10. Arduino 各种模块篇 摇杆模块

    Arduino的另外几种模块,我们常见的joystick摇杆模块. 用起来很爽,摇杆 有X,Y轴可调 这里有一篇非常想尽的示例代码: http://www.geek-workshop.com/foru ...