Javascript.RU

Создать новую тему Ответ
 
Опции темы Искать в теме
  #1 (permalink)  
Старый 17.06.2013, 17:25
Интересующийся
Отправить личное сообщение для kirill1989 Посмотреть профиль Найти все сообщения от kirill1989
 
Регистрация: 17.06.2013
Сообщений: 13

проблема работы Zoom скрипта
Доброго всем время суток, такая вот проблема, скрипт корректно увеличивает изображение в Firefox Opera IE, но в Chrome не работает в чем может быть причина?

// Product Image Viewer
function ImageExpander(oThumb, sImgSrc)
{
	// store thumbnail image and overwrite its onclick handler.
	this.oThumb = oThumb;
	this.oThumb.expander = this;
	this.oThumb.onclick = function() { this.expander.expand(); }
	
	// record original size
	this.smallWidth = oThumb.offsetWidth;
	this.smallHeight = oThumb.offsetHeight;	

	this.bExpand = true;
	this.bTicks = false;
	
	// self organized list
	if ( !window.aImageExpanders )
	{
		window.aImageExpanders = new Array();
	}
	window.aImageExpanders.push(this);

	// create the full sized image.
	this.oImg = new Image();
	this.oImg.expander = this;
	this.oImg.onload = function(){this.expander.onload();}
	this.oImg.src = sImgSrc;
}

ImageExpander.prototype.onload = function()
{
	this.oDiv = document.createElement("div");
	document.body.appendChild(this.oDiv);
	this.oDiv.appendChild(this.oImg);
	this.oDiv.style.position = "absolute";
	this.oDiv.expander = this;
	this.oDiv.onclick = function() {this.expander.toggle();};
	this.oImg.title = "Click to close";
	this.bigWidth = this.oImg.width;
	this.bigHeight = this.oImg.height;
	
	if ( this.bExpand )
	{
		this.expand();
	}
	else
	{
		this.oDiv.style.visibility = "hidden";
		this.oImg.style.visibility = "hidden";
	}
}

ImageExpander.prototype.toggle = function()
{
	this.bExpand = !this.bExpand;
	if ( this.bExpand )
	{
		for ( var i in window.aImageExpanders )
			if ( window.aImageExpanders[i] !== this )
				window.aImageExpanders[i].reduce();
	}
}

ImageExpander.prototype.expand = function()
{
	// set direction of expansion.
	this.bExpand = true;

	// set all other images to reduce
	for ( var i in window.aImageExpanders )
		if ( window.aImageExpanders[i] !== this )
//MOYE QQQ tak yak bez zakomentuvannya ne druzhilo z lightboxom dlya SWF
			//window.aImageExpanders[i].reduce();

	// if not loaded, don't continue just yet
	if ( !this.oDiv ) return;
	
	// hide the thumbnail
	this.oThumb.style.visibility = "hidden";
	
	// calculate initial dimensions
	this.x = findPosX(this.oThumb); //this.oThumb.offsetLeft;
	this.y = findPosY(this.oThumb); //this.oThumb.offsetTop;
	this.w = this.oThumb.clientWidth;
	this.h = this.oThumb.clientHeight;
	
	this.oDiv.style.left = this.x + "px";
	this.oDiv.style.top = this.y + "px";
	this.oImg.style.width = this.w + "px";
	this.oImg.style.height = this.h + "px";
	this.oDiv.style.visibility = "visible";
	this.oImg.style.visibility = "visible";
	
	// start the animation engine.
	if ( !this.bTicks )
	{
		this.bTicks = true;
		var pThis = this;
		window.setTimeout(function(){pThis.tick();},25);	
	}
}

ImageExpander.prototype.reduce = function()
{
	// set direction of expansion.
	this.bExpand = false;
}

ImageExpander.prototype.tick = function()
{
	// calculate screen dimensions
	var cw = document.body.clientWidth;
	var ch = document.body.clientHeight;
	var cx = document.body.scrollLeft + cw / 2;
	var cy =  findPosY(this.oThumb); //document.body.scrollTop + ch / 3;

	// calculate target
	var tw,th,tx,ty;
	if ( this.bExpand )
	{
		tw = this.bigWidth;
		th = this.bigHeight;
		if ( tw > cw )
		{
			th *= cw / tw;
			tw = cw;
		}	
		if ( th > ch )
		{
			tw *= ch / th;
			th = ch;
		}
		tx = cx - tw / 2;
		ty = cy - th / 2; 
	}
	else
	{
		tw = this.smallWidth;
		th = this.smallHeight;
		tx = findPosX(this.oThumb);
		ty = findPosY(this.oThumb);
	}	
	// move 5% closer to target
	var nHit = 0;
	var fMove = function(n,tn) 
	{
		var dn = tn - n;
		if ( Math.abs(dn) < 3 )
		{
			nHit++;
			return tn;
		}
		else
		{
			return n + dn / 10;
		}
	}
	this.x = fMove(this.x, tx);
	this.y = fMove(this.y, ty);
	this.w = fMove(this.w, tw);
	this.h = fMove(this.h, th);
	
	this.oDiv.style.left = this.x + "px";
	this.oDiv.style.top = this.y + "px";
	this.oImg.style.width = this.w + "px";
	this.oImg.style.height = this.h + "px";

	// if reducing and size/position is a match, stop the tick	
	if ( !this.bExpand && (nHit == 4) )
	{
		this.oImg.style.visibility = "hidden";
		this.oDiv.style.visibility = "hidden";
		this.oThumb.style.visibility = "visible";

		this.bTicks = false;
	}
	
	if ( this.bTicks )
	{
		var pThis = this;
		window.setTimeout(function(){pThis.tick();},25);
	}
}

function findPosX(obj)
{
	var curleft = 0;
	if(obj.offsetParent)
		while(1) 
		{
		  curleft += obj.offsetLeft;
		  if(!obj.offsetParent)
			break;
		  obj = obj.offsetParent;
		}
	else if(obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if(obj.offsetParent)
		while(1)
		{
		  curtop += obj.offsetTop;
		  if(!obj.offsetParent)
			break;
		  obj = obj.offsetParent;
		}
	else if(obj.y)
		curtop += obj.y;
	return curtop;
}


<a href=\"images/products/".$file_does_exist.".jpg\" onclick=\"this.href='javascript:void(0);';\"><img src=\"images/products/thumb_".$file_does_exist.".jpg\" title=\"Click to Magnify\" alt=\"Click to Magnify\" id=\"ProductImage".$curimage."\" onclick=\"new ImageExpander(this, 'images/products/".$file_does_exist.".jpg');\" width=\"150\" style=\"border:1px solid black; max-height:170px; width: expression(this.style.height > 175 ? \"175px\": \"auto\" );\"></a><br>
				
				
				         
								<a href=\"images/products/".$file_does_exist.".jpg\" onclick=\"this.href='javascript:void(0);';\"><img src=\"../tt/zoom.png\" width=\"152\" border=\"0\" title=\"Click to Magnify\" alt=\"Click to Magnify\" onclick=\"new ImageExpander(ProductImage".$curimage.", 'images/products/".$file_does_exist.".jpg');\"></a>


Сама кнопка zoom.png при нажатии которой не работает увеличение в chrome, а при нажатии на само изображение работает.

Заранее благодарен за ответ.

Последний раз редактировалось kirill1989, 17.06.2013 в 17:30.
Ответить с цитированием
Ответ


Опции темы Искать в теме
Искать в теме:

Расширенный поиск


Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Скорость работы js скрипта Severtain Общие вопросы Javascript 1 23.05.2013 21:12
Проблема с кодировками скрипта Zim_one Events/DOM/Window 23 15.02.2013 02:52
Подвисание работы скрипта mel63 jQuery 0 09.09.2011 16:41
проблема работы jQuery.corner на Webkit freebit jQuery 3 17.01.2010 01:23
Проблема понимания работы скрипта Diogo Общие вопросы Javascript 0 08.11.2008 17:52