Javascript QuickTime Like Viewer
Ceci est un essai expérimental d'affichage d'un panorama avec effet de déformation genre quicktime.
Testé uniquement avec FireFox sous linux pour le moment :-)
Y a un bug d'affichage à gérer au moment du bouclage. Et
il est surement possible d'optimiser tout ça :-)
Code
<script language='javascript' type='text/javascript'>
Function.prototype.bind = function(object) {
var __method = this;
return function() {
return __method.apply(object, arguments);
}
}
function Qt(zonew, zoneh, picw, pich, src) {
this.src = src;
this.bw = 10;
this.zonew = zonew;
this.zoneh = zoneh;
this.picw = picw;
this.pich = pich;
this.posx = picw-100;
}
Qt.prototype.affiche = function() {
var qt = document.getElementById('qt');
qt.style.height = this.zoneh + 'px';
qt.style.width = this.zonew + 'px';
qt.style.overflow = 'hidden';
qt.style.position = 'relative';
qt.innerHTML = '';
var w = this.bw;
var ox = 0;
for(var px=0;px<this.zonew;px+=w) {
var e = document.createElement('div');
e.style.width = w + 'px';
e.style.height = this.zoneh + 'px';
e.style.left = px + 'px';
e.style.top = '0';
e.style.position = 'absolute';
e.style.overflow = 'hidden';
var img = document.createElement('img');
img.src = this.src;
img.style.left = - ((this.picw + px + this.posx)%this.picw) + 'px';
img.style.width = this.picw + 'px';
img.style.position = 'absolute';
var rx = px - (this.zonew/2);
var amp = 200;
d = amp - amp*Math.cos(rx/180);
var sh = (this.pich + Math.round(d));
img.style.top = (-Math.round((sh-this.pich)/2)) + 'px';
img.style.height = sh + 'px';
img.qt = this;
img.dx = rx/(this.zonew/2);
img.onmouseover = this.over.bind(img);
e.appendChild(img);
qt.appendChild(e);
}
}
Qt.prototype.over = function() {
this.qt.bw = Math.max(2, Math.abs(Math.round(this.dx*40)));
this.qt.posx += Math.round(this.dx*30);
this.qt.posx %= this.qt.picw;
this.qt.affiche();
}
function addEvent(obj, evType, fn) {
if (obj.addEventListener){
obj.addEventListener(evType, fn, true);
return true;
} else if (obj.attachEvent){
var r = obj.attachEvent("on"+evType, fn);
return r;
} else {
return false;
}
}
var qt = new Qt(480, 300, 2836, 300, 'images/pano.jpg');
addEvent(window, 'load',
function() {
qt.affiche();
}
);
</script>
<div style='margin: 30px' id='qt'></div>
Ludomedia - Marc Chappuis - Ch. des Mouettes 14 - 1007 Lausanne - 021 634 80 07