Модераторы: Sardar, Aliance
  

Поиск:

Ответ в темуСоздание новой темы Создание опроса
> Прошу помощи в разборе скрипта, Помогите со скриптом, плизз( 
:(
    Опции темы
klboris
  Дата 12.1.2010, 16:19 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Новичок



Профиль
Группа: Участник
Сообщений: 7
Регистрация: 12.1.2010

Репутация: нет
Всего: нет



Люди помоготе разобраться в скрипте. Нужно чтобы фреймы менялись автоматически через определенное время. На данный момент меняются только при нажатии на скролеры "вперед" и "назад".
зы. Не пинайте сильно я не очень разбираюсь в java

Скрипт: 
Код

// slide 

var SimpleSlide = new Class({
    initialize: function(container,options) {
        this.container = container;
        this.options = options;
        var automated;
        var direction;
        var hideshow_flag;

        this.hideshow_flag=true;

        if(this.options) this.direction = this.options.direction;
        else this.direction = "forward";

        //    Is it on autorun or manual?
        if (this.direction!="pause")
        {
        if(this.options.auto == "loop" || this.options.auto == "once") {

           this.automated = this.slider.periodical(this.options.time,this,$(this.container));
        } else {
            this.slider($(this.container))
        }
        }
    },

    next: function(type) {
             if(this.options.auto == "loop" || this.options.auto == "once") {
               this.run();
             };
              this.options.type=type;
              this.direction="forward";
              this.slider($(this.container));
     },
    prev: function(type) {
               if(this.options.auto == "loop" || this.options.auto == "once") {
               this.run();
             };
              this.options.type=type;
              this.direction="back";
              this.slider($(this.container));
     },
    pause: function() {
              this.direction="pause";
              this.slider($(this.container));
     },
    run: function() {
           this.direction="forward";
           this.automated = this.slider.periodical(this.options.time,this,$(this.container));
                             },
    slider: function(container) {
        if ((this.options.auto == "once" || this.options.auto == "loop") && this.direction == "run")
        {
           $clear(this.automated);
        }else{
        var child;
        // Get all child nodes to scroll between.
        var children = container.getChildren().getChildren()[0];
        // Run through all child nodes to see if there is a tagged one.
        children.each(function(e) {
            // If there is, make it current child.
            if(e.id == "currentChild") {
                child = e;
            }
           // alert(e.id);
        });
        //alert(this.direction);

            if(!child) {
                // If there isn't, make the first one current child.
                if(this.direction == "forward") {
                    child = children[0].getNext();
                }
                else if(this.direction == "back") {
                    child = container.getChildren()[0].getLast();
                }
            } else {
            // Are we going to the next or previous node?
                if(this.direction == "forward") {
                    var lastElement = container.getChildren()[0].getLast();
                    // Stops the loop at the last element.
                    if(lastElement == child.getNext() && this.options.auto == "once") $clear(this.automated);
                    // Is the current child the last node? Then set the first node as child, otherwise set the next node as child.
                    if(lastElement == child) child = children[0];
                    else child = child.getNext();
                }
                else if(this.direction == "back") {
                    var firstElement = container.getChildren()[0].getFirst();
                    // Stops the loop at the last element.
                    if(firstElement == child.getPrevious() && this.options.auto == "once") $clear(this.automated);
                    // Is the current child the last node? Then set the first node as child, otherwise set the next node as child.
                    if(firstElement == child) child = container.getChildren()[0].getLast();
                    else child = child.getPrevious();}};
                
                
        // Is the child defined?
        if(child && this.direction != "pause") {
            // Which type of slider is defined?
            if(this.options.type == "scroll") this.scroll(container,children,child);
            else if(this.options.type == "fade") this.fade(container,children,child);
            else if(this.options.type == "scrollfade") this.scrollfade(container,children,child);
        }
        if(child && this.direction != "run") {
            // Which type of slider is defined?
            if(this.options.type == "scroll") this.scroll(container,children,child);
            else if(this.options.type == "fade") this.fade(container,children,child);
            else if(this.options.type == "scrollfade") this.scrollfade(container,children,child);
        }
        }
    },

    init_vertical: function() {

       $(this.container).setStyle('position','relative');
       var children = $(this.container).getChildren().getChildren()[0];
       var i;
       var s_h;
       var s_w;
       var b_w;

       b_w=$(this.container).getStyle('border-width').toInt();

       s_h=$(this.container).getSize().size.y-2*b_w;
       s_w=$(this.container).getSize().size.x-2*b_w;

       //s_h=100;
       //s_w=600;

       i=0;
       children.each(function(e) {
          if (i!=0)
          {
            e.id = "currentChild";
            $('currentChild').setStyle('position','relative');
            $('currentChild').setStyle('left',0-s_w*i);
            $('currentChild').setStyle('top',0+s_h*i);
            e.id = "";
          }
          i++;
        });

        children.each(function(e) {
                e.id = "";
            });
     },
    init_horizontal: function() {
 $(this.container).setStyle('position','relative');
       var children = $(this.container).getChildren().getChildren()[0];
       var i;
       var s_h;
       var s_w;
       var b_w;

       b_w=$(this.container).getStyle('border-width').toInt();

       s_h=$(this.container).getSize().size.y-2*b_w;
       s_w=$(this.container).getSize().size.x-2*b_w;

       //s_h=100;
       //s_w=600;

       i=0;
       children.each(function(e) {
          if (i!=0)
          {
            e.id = "currentChild";
            $('currentChild').setStyle('position','relative');
            $('currentChild').setStyle('left',0);
            $('currentChild').setStyle('top',0);
            e.id = "";
          }
          i++;
        });
     },
    scroll: function(container,children,child) {
        // Make it a scroll slide.
        var scroll = new Fx.Scroll(container,{duration: this.options.duration, onComplete: function() {
            // Remove tags from all child nodes.
            children.each(function(e) {
                e.id = "";
            });
            // Tag this child as current
            child.id = "currentChild";
        }}).toElement(child);
    },
    fade: function(container,children,child) {
        // Make it a fade slide
        var fade = new Fx.Style(container,'opacity',{duration: this.options.duration, onComplete: function() {
            new Fx.Scroll(container,{duration: 1,onComplete: function() {
                // Remove tags from all child nodes.
                children.each(function(e) {
                    e.id = "";
                });
                // Tag this child as current
                child.id = "currentChild";
                new Fx.Style(container,'opacity').start(0.01,1);
            }}).toElement(child);
        }})
        fade.start(1,0.01);
    },
    scrollfade: function(container,children,child) {
        // In case you input the miliseconds as a string instead of integer.
        var durationInt = this.options.duration.toInt();
        // Make it a scrollfade slide
        var fade = new Fx.Style(container,'opacity',{duration: (durationInt/2)})
        fade.start(1,0.01).chain(function() {
            fade.start(0.01,1);
        });
        new Fx.Scroll(container,{duration: durationInt, onComplete: function() {
            // Remove tags from all child nodes.
            children.each(function(e) {
                e.id = "";
            });
            // Tag this child as current
            child.id = "currentChild";
        }}).toElement(child);
    },
    hide_and_show_fade:function()
    {
       var fade = new Fx.Style($(this.container),'opacity',{duration: this.options.duration});
       if (this.hideshow_flag)
       {
         fade.start(1,0.01);
       }else
       {
         fade.start(0.01,1);
       }
       this.hideshow_flag=!this.hideshow_flag;
    }
});


Код в странице: 

Код

<script type='text/javascript'>
var  slidebox = new SimpleSlide("SlideBox",{type: "fade", direction: "stop", auto: "loop", time: 3000, duration: 500});
var type_slider='fade';
</script>


Помогите плизз очень нужно  smile 

Это сообщение отредактировал(а) 12345c - 14.1.2010, 19:01
PM MAIL   Вверх
firedrago
Дата 12.1.2010, 16:24 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Бывалый
*


Профиль
Группа: Участник
Сообщений: 170
Регистрация: 22.9.2005

Репутация: нет
Всего: 3



форумом ошибся -> http://forum.vingrad.ru/forum/Javascript.html
PM MAIL   Вверх
LSD
Дата 12.1.2010, 16:26 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Leprechaun Software Developer
****


Профиль
Группа: Модератор
Сообщений: 15718
Регистрация: 24.3.2004
Где: Dublin

Репутация: нет
Всего: 538



Цитата(klboris @  12.1.2010,  16:19 Найти цитируемый пост)
зы. Не пинайте сильно я не очень разбираюсь в java

Начни с того, что выучи разницу между Java и JavaScript.


--------------------
Disclaimer: this post contains explicit depictions of personal opinion. So, if it sounds sarcastic, don't take it seriously. If it sounds dangerous, do not try this at home or at all. And if it offends you, just don't read it.
PM MAIL WWW   Вверх
klboris
Дата 12.1.2010, 16:45 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Новичок



Профиль
Группа: Участник
Сообщений: 7
Регистрация: 12.1.2010

Репутация: нет
Всего: нет



НУ вот просил же не пинать сильно, лучше по делу скажите что нибудь  smile 
PM MAIL   Вверх
NNaarreekk
Дата 12.1.2010, 18:54 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Опытный
**


Профиль
Группа: Участник
Сообщений: 768
Регистрация: 23.6.2007
Где: Армения

Репутация: 2
Всего: 3



Цитата(klboris @  12.1.2010,  18:45 Найти цитируемый пост)
НУ вот просил же не пинать сильно...

Это они не сильно! smile 

по вопросу:
Код

tt=SetTimeout("foo()",3000);

Где foo() надо заменить функцией которая срабатывает когда жмешь на кнопку вперед а 3000 время в милисекундах 3000= 3 сек.
PM MAIL WWW   Вверх
klboris
Дата 12.1.2010, 22:10 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Новичок



Профиль
Группа: Участник
Сообщений: 7
Регистрация: 12.1.2010

Репутация: нет
Всего: нет



Если честно я так и не понял  куда вставлять этот код

Код

tt=SetTimeout("foo()",3000);


Судя по коду

Код

    next: function(type) {
             if(this.options.auto == "loop" || this.options.auto == "once") {
               this.run();
             };
              this.options.type=type;
              this.direction="forward";
              this.slider($(this.container));
     },


то переменная вперед это --> forward

и значит код получается 

Код

tt=SetTimeout("forward()",3000);


а куда вставлять?

зы. Мне легче хостинг на линухе поднять, чем здесь. Объясните плизз на пальцах.  smile 
PM MAIL   Вверх
NNaarreekk
Дата 13.1.2010, 12:19 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Опытный
**


Профиль
Группа: Участник
Сообщений: 768
Регистрация: 23.6.2007
Где: Армения

Репутация: 2
Всего: 3



Как я понял если заменить в коде stop на run то должно само сработать так как у тебя в классе есть функция для поочередной замены.

Попробуй так:

Код

<script type='text/javascript'>
var  slidebox = new SimpleSlide("SlideBox",{type: "fade", direction: "run", auto: "loop", time: 3000, duration: 500});
var type_slider='fade';
</script>

PM MAIL WWW   Вверх
klboris
Дата 13.1.2010, 15:12 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Новичок



Профиль
Группа: Участник
Сообщений: 7
Регистрация: 12.1.2010

Репутация: нет
Всего: нет



Цитата(NNaarreekk @  13.1.2010,  12:19 Найти цитируемый пост)

Как я понял если заменить в коде stop на run то должно само сработать так как у тебя в классе есть функция для поочередной замены.

Попробуй так:
   
<script type='text/javascript'>
var  slidebox = new SimpleSlide("SlideBox",{type: "fade", direction: "run", auto: "loop", time: 3000, duration: 500});
var type_slider='fade';
</script>




нет к сожалению это не так smile . насколько я понимаю функция рун срабатывает только при клики мыши а не автоматом  smile 

Это сообщение отредактировал(а) klboris - 13.1.2010, 15:14
PM MAIL   Вверх
NNaarreekk
Дата 13.1.2010, 15:36 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Опытный
**


Профиль
Группа: Участник
Сообщений: 768
Регистрация: 23.6.2007
Где: Армения

Репутация: 2
Всего: 3



Еще так оппробуй, если и так не получится то уже не знаю.
Но точно могу сказать что твой код дает возможность поочередного показывания.
Код

<script type='text/javascript'>
var  slidebox = new SimpleSlide("SlideBox",{type: "fade", direction: "slider", auto: "loop", time: 3000, duration: 500});
var type_slider='fade';
</script>

PM MAIL WWW   Вверх
klboris
Дата 13.1.2010, 20:35 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Новичок



Профиль
Группа: Участник
Сообщений: 7
Регистрация: 12.1.2010

Репутация: нет
Всего: нет



Не хочет собака. 
Про авто я тоже предполагаю там написано:

//    Is it on autorun or manual?
PM MAIL   Вверх
klboris
  Дата 14.1.2010, 17:50 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Новичок



Профиль
Группа: Участник
Сообщений: 7
Регистрация: 12.1.2010

Репутация: нет
Всего: нет



Что, так никто и не поможет?  smile  smile 

Пример здесь, вверху сайта http://complexpc.ru/

Это сообщение отредактировал(а) klboris - 14.1.2010, 17:58
PM MAIL   Вверх
12345c
Дата 14.1.2010, 18:31 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Круглый
****


Профиль
Группа: Vingrad developer
Сообщений: 2018
Регистрация: 26.12.2005
Где: наша не пропадала ?

Репутация: 6
Всего: 101



Цитата(klboris @  12.1.2010,  22:10 Найти цитируемый пост)
и значит код получается код Javascript1:tt=SetTimeout("forward()",3000);
Нет, по тексту - это функция next()

Код

<script type='text/javascript'>
var  slidebox = new SimpleSlide("SlideBox",{type: "fade", direction: "stop", auto: "loop", time: 3000, duration: 500});
var type_slider='fade';
onload = function(){ii=setInterval("slidebox.next",3000);}
</script>
и кнопку "Стоп", если надо, с clearInterval(ii); .

А лучше покажите источник этого кода . Есть вопросы. "new Class" - это значит он для Mootools?
И "auto: "loop"" = это значит, что скипт должен и без того работать, без setInterval?
И тогда вопрос, не забыли ли Вы подключить Mootools по инструкции к скрипту?

Вот нашёл работающий код другого плагина под jQuery: http://www.joshskeen.com/posts/view/16/sim...e-jquery-plugin

Цитата(NNaarreekk @  12.1.2010,  18:54 Найти цитируемый пост)
SetTimeout(
Ошибка - пишется с мал.буквы.

Добавлено @ 18:40
Да, посмотрел, как вызывается.

Пишите
slidebox.next(type_slider);
Код

<script type='text/javascript'>
var  slidebox = new SimpleSlide("SlideBox",{type: "fade", direction: "stop", auto: "loop", time: 3000, duration: 500});
var type_slider='fade';
onload = function(){ii=setInterval("slidebox.next(type_slider)", 3000);}
</script>
и кнопку "Стоп", если надо, с clearInterval(ii); .
, чтобы не разбираться, почему не работает.

Добавлено @ 18:46
А лучше вместо onload = function(){ii=setInterval("slidebox.next(type_slider)", 3000);} - 

Код

window.addEvent('domready', function() {
  ii=setInterval("slidebox.next(type_slider)", 3000); 
});


====
или вот в чём дело. Отладчик Firebug показывает ошибку:
     
missing ) after argument list
[Break on this error] itleInSystemVar + '" onclick="adhide()" ...предложение!</a></td></tr></table></td><

возможно, она не даёт выполниться скриптам. Уберите рекламу, которая даёт эту ошибку.

Это сообщение отредактировал(а) 12345c - 14.1.2010, 18:56


--------------------
Google Code Playground - онлайн-отладка своих примеров HTML+JS без регистрации, с сохранением по URL, без кириллицы. Go
PM WWW   Вверх
klboris
  Дата 14.1.2010, 21:16 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Новичок



Профиль
Группа: Участник
Сообщений: 7
Регистрация: 12.1.2010

Репутация: нет
Всего: нет



12345c спасибо огромное,  все работает  smile 
PM MAIL   Вверх
  
Ответ в темуСоздание новой темы Создание опроса
0 Пользователей читают эту тему (0 Гостей и 0 Скрытых Пользователей)
0 Пользователей:
« Предыдущая тема | JavaScript: для новичков | Следующая тема »


 




[ Время генерации скрипта: 0.1216 ]   [ Использовано запросов: 22 ]   [ GZIP включён ]


Реклама на сайте     Информационное спонсорство

 
По вопросам размещения рекламы пишите на vladimir(sobaka)vingrad.ru
Отказ от ответственности     Powered by Invision Power Board(R) 1.3 © 2003  IPS, Inc.