Слайдшоу с возможностью клика

Разработка своих веб-приложений и страничек

Слайдшоу с возможностью клика

Сообщение stDRagon » 17 окт 2009, 17:54

короче сталкнулся спроблемой обьеденения 2 кодов, имею функцианирующие код слайдшоу и код увеличения изображения при нажатии на него но чето не получается их обеденить, ошибку найти немогу мож кто поможет
скрипт слайдшоу:
Код: Выделить всёРазвернуть
<script>
var t1=null;
var slide1=new Array();
slide1[0]="./ftp/Foto/1/P1000026.jpg";
slide1[1]="./ftp/Foto/1/P1000027.jpg";
slide1[2]="./ftp/Foto/1/P1000030.jpg";
var i=0;

function loadSlide(){
setInterval("Slide()",10000)
}

function Slide(){
i++;
if (i>3)i=0;
pic.src=slide1[i]
}
</script>

код в документе:
Код: Выделить всёРазвернуть
<img src="./ftp/Foto/1/P1000026.jpg" name=pic width="200" Height=133 border="0"  ">

скрипт увеличения при клики на ресунок:
Код: Выделить всёРазвернуть
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 reduce.";
   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 )
         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 = this.oThumb.offsetLeft;
   this.y = 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 = document.body.scrollTop + ch / 2;

   // 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 = this.oThumb.offsetLeft;
      ty = this.oThumb.offsetTop;
   }   
   // 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);
   }
}

код в документе:
Код: Выделить всёРазвернуть
<a href="big.jpg" onclick="this.href = 'javascript:void(0);';">
<img src="small.jpg" border="0" onClick="new ImageExpander(this, 'big.jpg');">
</a>

у меня короче получилось сделать шобы слайдшоу менялось, но при клике открывается токо 1 ресунок, а шобы открывался pic мне не получается :unknown:
Код: Выделить всёРазвернуть
<a href="./ftp/Foto/1/P1000026.jpg" onclick="this.href = 'javascript:void(0);';">
<img src="./ftp/Foto/1/P1000026.jpg" name=pic width="200" Height=133 border="0"  onClick="new ImageExpander(this, './ftp/Foto/1/P1000026.jpg');">
</a>

вся проблема в последних 3 строчках =(
stDRagon
Начинающий участник
 
Сообщения: 6
Зарегистрирован: 26 фев 2009, 10:15

Re: Слайдшоу с возможностью клика

Сообщение Zver » 17 окт 2009, 18:26

:D
Код: Выделить всёРазвернуть
onClick="new ImageExpander(this, 'big.jpg');"

Как я понял это функция увелечение изображения.
Поэтому для смены картинки используй двойной щелчок:
Код: Выделить всёРазвернуть
onDbClick="Slide();"

Если не подходит поменяй онКлик и ОнДбКлик.
Zver
Активный участник
 
Сообщения: 1333
Зарегистрирован: 18 дек 2008, 18:51
Откуда: Саратов, Заводской

Re: Слайдшоу с возможностью клика

Сообщение stDRagon » 17 окт 2009, 18:59

Нимного не прально выразился, обясню более конкретно:
Код: Выделить всёРазвернуть
onClick="new ImageExpander(this, './ftp/Foto/1/P1000026.jpg');"

вот тут у меня не получается вместо ./ftp/Foto/1/P1000026.jpg мне надо передать функцией не 1 конкретный ресунок, а тот который скопирован в pic, но кода я пишу
Код: Выделить всёРазвернуть
onClick="new ImageExpander(this, pic);"

скрипт не работает, я и сам понимаю что что-то где-то не так написал, токо из-за малого опыта ни хрена не пойму что именно
stDRagon
Начинающий участник
 
Сообщения: 6
Зарегистрирован: 26 фев 2009, 10:15

Re: Слайдшоу с возможностью клика

Сообщение Zver » 17 окт 2009, 19:54

Код: Выделить всёРазвернуть
onClick="new ImageExpander(this, './images/pic.gif');" 

А ты формат картинки указываешь ? И правильно ли указал путь ?
Zver
Активный участник
 
Сообщения: 1333
Зарегистрирован: 18 дек 2008, 18:51
Откуда: Саратов, Заводской

Re: Слайдшоу с возможностью клика

Сообщение stDRagon » 18 окт 2009, 12:40

pic это у меня не кортинка, а ссылка на картинку
Код: Выделить всёРазвернуть
pic.src=slide1[i]

которая меняется

попробывал сделать вот так
Код: Выделить всёРазвернуть
onClick="new ImageExpander(this, pic.src);"

теперь увеличивается текущий ресунок, но когда слайдменяется и кликаю на новый ресунок то увеличевается старый.
stDRagon
Начинающий участник
 
Сообщения: 6
Зарегистрирован: 26 фев 2009, 10:15


Вернуться в PHP, HTML, CSS...

Кто сейчас на конференции

Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 16

cron