kacsa_src_4

[realcontent]

[div align=”center”]
[div id=”holder” style=”position: relative; width: 640px; height: 480px; overflow: hidden”]
[/div]
[/div]

[script]

function createKacsa(holderDiv){
this.src = “//csillagtura.ro/wp-content/uploads/2015/08/kacsa_src_4.svg”;
this.originalWidthUnit = 64;
this.originalWidth = 640;
this.originalHeight = 480;
this.originalRelativeChildLeft = 342;
this.originalRelativeChildTop = 346;
this.originalChildHeight = 103;
this.originalCenterX = 435.5;
this.originalCenterY = 440.5;

this.id = Math.random();
this.holder = holderDiv;
this.img = false;

this.widthPerHeight = function (){
return this.originalWidth/this.originalHeight;
};

this.left = 0;
this.top = 0;
this.width = this.originalWidth;
this.height = this.originalHeight;

this.child = false;
this.relativeChildLeft = 0;
this.relativeChildTop = 0;
this.childWidth = 0;
this.childHeight = 0;

this.roundTheSizes = function (){
var delta = 0.01;
for (var q = 1; q<150; q++)
if (Math.abs(this.width – this.originalWidthUnit*q) < delta){
this.width = this.originalWidthUnit*q;
this.height = this.width/this.widthPerHeight();
}
}
this.setWidth = function (w){
this.width = w;
this.height = w/this.widthPerHeight();
this.roundTheSizes();
}

this.setHeight = function (h){
this.height = h;
this.width = h * this.widthPerHeight();
this.roundTheSizes();
}

this.setChildSizes = function (){
this.relativeChildLeft = this.width*this.originalRelativeChildLeft / this.originalWidth;
this.childHeight = this.originalChildHeight * this.height / this.originalHeight;
this.childWidth = this.childHeight * this.widthPerHeight();
this.relativeChildTop = this.height * this.originalRelativeChildTop / this.originalHeight;
}

this.makeImgTag = function (){
this.img = document.createElement(“img”);
this.img.src = this.src;
this.img.setAttribute(“style”,
“position: absolute; left: 0px; top: 0px; width: 0px; height: 0px;”);
this.img.id = this.id;
holder.appendChild(this.img);
}

this.render = function (){
if (!this.img) this.makeImgTag();
this.img.setAttribute(“style”,
“position: absolute; “+
“left: “+this.left+”px; “+
“top: “+this.top+”px; “+
“width: “+this.width+”px; “+
“height: “+this.height+”px”
);
if (this.child){
this.setChildSizes();
this.child.left = this.left+this.relativeChildLeft;
this.child.top = this.top+this.relativeChildTop;
this.child.setWidth(this.childWidth);

this.child.render();
}
}

this.removeChildKacsa = function (){
if (!this.child) return;
this.child.removeChildKacsa();
if (this.child.img) holder.removeChild(this.child.img);
this.child = false;
}

this.removeFromDOMbutKeepChildren = function (){
this.holder.removeChild(this.img);
}

this.appendChildKacsa = function (c){
this.removeChildKacsa();
this.child = c;
}

this.createChildKacsa = function (){
this.removeChildKacsa();
this.child = new createKacsa(this.holder);
}

this.nest = function (level){
if (level < 0) level = 0;
this.removeChildKacsa();
if (level < 1) return ; var t = this; while (level > 0){
t.child = new createKacsa(t.holder);
t = t.child;
level–;
}
}

this.getNestLevel = function (){
var t = this;
var level = 0;
while (t.child){
t = t.child;
level++;
}
return level;
}

this.haveAtLeastThisManyNested = function (level){
var t = this;
while (t.child){
level–;
t = t.child;
}
while (level > 0){
t.child = new createKacsa(t.holder);
t = t.child;
level–;
}
}

this.zoomAbsolute = function (factor){
this.setWidth(this.originalWidth*factor);
var cx = this.originalCenterX * factor;
var cy = this.originalCenterY * factor;
this.left = this.originalCenterX – cx;
this.top = this.originalCenterY – cy;
this.render();
}
this.zoomRelative = function (factor){
this.setWidth(this.width*factor);
this.zoomAbsolute(this.width / this.originalWidth);
}

return this;
}

var topKacsa = false;
var kacsaFactorInit = 1;
var kacsaFactor = kacsaFactorInit;

if(! navigator.userAgent.match(/Android/i) &&
! navigator.userAgent.match(/webOS/i) &&
! navigator.userAgent.match(/iPhone/i) &&
! navigator.userAgent.match(/iPod/i) &&
! navigator.userAgent.match(/iPad/i) &&
! navigator.userAgent.match(/Blackberry/i) )
{
var kacsaTimer = 50;
var kacsaFactorDesired = 1.02;
var kacsaStep = 0.00005;
var kacsaNest = 10;
var kacsaMaxW = 7;
}else{
var kacsaTimer = 100;
var kacsaFactorDesired = 1.2;
var kacsaStep = 0.1;
var kacsaNest = 3;
var kacsaMaxW = 5.5;
}

function initKacsa(){
topKacsa = new createKacsa(document.getElementById(“holder”));
//topKacsa.haveAtLeastThisManyNested(10);
topKacsa.render();
}

function kacsaCicle(){
if (topKacsa.width > topKacsa.originalWidth*kacsaMaxW){
topKacsa.removeFromDOMbutKeepChildren();
topKacsa = topKacsa.child;
}
topKacsa.haveAtLeastThisManyNested(kacsaNest);
topKacsa.zoomRelative(kacsaFactor);

kacsaFactor = kacsaFactor + kacsaStep;
if (kacsaFactor > kacsaFactorDesired) kacsaFactor = kacsaFactorDesired;

setTimeout(“kacsaCicle()”, kacsaTimer);
}
function kacsaCicleStart(){
setTimeout(“kacsaCicle()”, kacsaTimer);
}

initKacsa();
setTimeout(“kacsaCicleStart()”, 5000);

[/script]

facebooktwittergoogle_plusredditpinterestlinkedinmail