Javascript.RU

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

Прошу помочь
Здравствуйте, ув. форумчане.
Столкнулся с одной проблемой,прошу кто сможет помочь...
У меня на сайте стоит слайдер,он не прокручивается автоматом,а мне нужно что бы он сам крутился автоматом через определенное время.

Вот собственно код:
(function($) {
  $.fn.parallaxSlider = function(options) {
    var opts = $.extend({}, $.fn.parallaxSlider.defaults, options);
    return this.each(function() {
      var $pxs_container   = $(this),
      o         = $.meta ? $.extend({}, opts, $pxs_container.data()) : opts;
      
      //the main slider
      var $pxs_slider    = $('.pxs_slider',$pxs_container),
      //the elements in the slider
      $elems      = $pxs_slider.children(),
      //total number of elements
      total_elems    = $elems.length,
      //the navigation buttons
      $pxs_next    = $('.pxs_next',$pxs_container),
      $pxs_prev    = $('.pxs_prev',$pxs_container),
      //the bg images
      $pxs_bg1    = $('.pxs_bg1',$pxs_container),
      $pxs_bg2    = $('.pxs_bg2',$pxs_container),
      $pxs_bg3    = $('.pxs_bg3',$pxs_container),
      //current image
      current      = 0,
      //the thumbs container
      $pxs_thumbnails = $('.pxs_thumbnails',$pxs_container),
      //the thumbs
      $thumbs      = $pxs_thumbnails.children(),
      //the interval for the autoplay mode
      slideshow,
      //the loading image
      $pxs_loading  = $('.pxs_loading',$pxs_container),
      $pxs_slider_wrapper = $('.pxs_slider_wrapper',$pxs_container);
        
      //first preload all the images
      var loaded    = 0,
      $images    = $pxs_slider_wrapper.find('img');
        
      $images.each(function(){
        var $img  = $(this);
        $('<img/>').load(function(){
        
          ++loaded;
          
          if(loaded  == total_elems*2){
          
            $pxs_loading.hide();
            $pxs_slider_wrapper.show();
              
            //one images width (assuming all images have the same sizes)
            var one_image_w    = $pxs_slider.find('img:first').width();
      
            /*
            need to set width of the slider,
            of each one of its elements, and of the
            navigation buttons
             */
            setWidths($pxs_slider,
            $elems,
            total_elems,
            $pxs_bg1,
            $pxs_bg2,
            $pxs_bg3,
            one_image_w,
            $pxs_next,
            $pxs_prev);
        
            var spaces  = one_image_w/(total_elems+1);
            $thumbs.each(function(i){

            });
              
            //make the first thumb be selected
            highlight($thumbs.eq(0));
              
            //slide when clicking the navigation buttons
            $pxs_next.bind('click',function(){
               if (slideshow)
               {
                  s_t();
               }
              ++current;
              if(current >= total_elems)
                if(o.circular)
                  current = 0;
              else{
                --current;
                return false;
              }
              highlight($thumbs.eq(current));
              slide(current,
              $pxs_slider,
              $pxs_bg3,
              $pxs_bg2,
              $pxs_bg1,
              o.speed,
              o.easing,
              o.easingBg,
              o.animDone); // ДОБАВРР›
            });
            
            $pxs_prev.bind('click',function(){
              --current;
              if(current < 0)
                if(o.circular)
                  current = total_elems - 1;
              else{
                ++current;
                return false;
              }
              highlight($thumbs.eq(current));
              slide(current,
              $pxs_slider,
              $pxs_bg3,
              $pxs_bg2,
              $pxs_bg1,
              o.speed,
              o.easing,
              o.easingBg,
              o.animDone); // ДОБАВРР›
            });
        
            /*
            clicking a thumb will slide to the respective image
             */
            $thumbs.bind('click',function(){
              var $thumb  = $(this);
              highlight($thumb);
              //if autoplay interrupt when user clicks
              if(o.auto)
                clearInterval(slideshow);
              current   = $thumb.index();
              slide(current,
              $pxs_slider,
              $pxs_bg3,
              $pxs_bg2,
              $pxs_bg1,
              o.speed,
              o.easing,
              o.easingBg,
              o.animDone); // ДОБАВРР›
            });
        
          
             var int_c = 0;
        
            /*
            activate the autoplay mode if
            that option was specified
             */
           
             function s_t(){
             
               if(o.auto != 0){
                 o.circular  = true;
                 if (slideshow) clearInterval(slideshow);
                 slideshow  = setInterval(function(){
                    int_c = 1;
                   $pxs_next.trigger('click');
                   int_c = 0;
                 },o.auto);
               };
            
            }
            
            s_t();
        
            /*
            when resizing the window,
            we need to recalculate the widths of the
            slider elements, based on the new windows width.
            we need to slide again to the current one,
            since the left of the slider is no longer correct
             */
            $(window).resize(function(){
              w_w  = $(window).width();
              setWidths($pxs_slider,$elems,total_elems,$pxs_bg1,$pxs_bg2,$pxs_bg3,one_image_w,$pxs_next,$pxs_prev);
              slide(current,
              $pxs_slider,
              $pxs_bg3,
              $pxs_bg2,
              $pxs_bg1,
              1,
              o.easing,
              o.easingBg);
            });

          }
        }).error(function(){
        }).attr('src',$img.attr('src'));
      });
        
        
        
    });
  };
  
  //the current windows width
  var w_w        = $(window).width();
  
  var slide      = function(current,
  $pxs_slider,
  $pxs_bg3,
  $pxs_bg2,
  $pxs_bg1,
  speed,
  easing,
  easingBg,
  animDone){
    var slide_to  = parseInt(-w_w * current);
    $pxs_slider.stop().animate({
      left  : slide_to + 'px'
    },speed, easing, function () {
       var parent=$pxs_slider.children().eq(current);
       if (animDone) animDone.apply(this, [parent]);
    });
    $pxs_bg3.stop().animate({
      left  : slide_to/2 + 'px'
    },speed, easingBg);
    $pxs_bg2.stop().animate({
      left  : slide_to/4 + 'px'
    },speed, easingBg);
    $pxs_bg1.stop().animate({
      left  : slide_to/8 + 'px'
    },speed, easingBg);
  };
  
  var highlight    = function($elem){
    $elem.siblings().removeClass('selected');
    $elem.addClass('selected');
  };
  
  var setWidths    = function($pxs_slider,
  $elems,
  total_elems,
  $pxs_bg1,
  $pxs_bg2,
  $pxs_bg3,
  one_image_w,
  $pxs_next,
  $pxs_prev){
    /*
    the width of the slider is the windows width
    times the total number of elements in the slider
     */
    var pxs_slider_w  = w_w * total_elems;
    $pxs_slider.width(pxs_slider_w + 'px');
    //each element will have a width = windows width
    $elems.width(w_w + 'px');
    /*
    we also set the width of each bg image div.
    The value is the same calculated for the pxs_slider
     */
    $pxs_bg1.width(pxs_slider_w + 'px');
    $pxs_bg2.width(pxs_slider_w + 'px');
    $pxs_bg3.width(pxs_slider_w + 'px');
  };
  
  $.fn.parallaxSlider.defaults = {
    auto      : 5,  //how many seconds to periodically slide the content.
                //If set to 0 then autoplay is turned off.
    speed      : 1600,//speed of each slide animation
    easing      : 'easeInOutCubic',//easing effect for the slide animation
    easingBg    : 'easeInOutCubic',//easing effect for the background animation
    circular    : true,//circular slider
    thumbRotation  : true, //the thumbs will be randomly rotated
    
    animDone : null // ДОБАВРР› СВОЙСТВО
  };
  //easeInOutExpo,easeInBack
})(jQuery);
Ответить с цитированием
  #2 (permalink)  
Старый 13.06.2012, 15:10
Новичок на форуме
Отправить личное сообщение для Gandjubass Посмотреть профиль Найти все сообщения от Gandjubass
 
Регистрация: 13.06.2012
Сообщений: 3

up!
Ответить с цитированием
  #3 (permalink)  
Старый 13.06.2012, 15:39
sinistral
Посмотреть профиль Найти все сообщения от melky
 
Регистрация: 28.03.2011
Сообщений: 5,418

После загрузки плагина, и перед его инициализацией:
(function(){
	var proxied = $.fn.parallaxSlider;
	if (!proxied) {
		throw new Error("There is no parallax slider");
	}
	$.extend(proxied, {
		"next": function(){
			$(this).data("ps.next").trigger("click");
		},
		"prev": function(){
			$(this).data("ps.prev").trigger("click");
		}
	});
	$.fn.parallaxSlider = function(options) {
		$(this).each(function(that){
			that = $(that);
			that.data("ps.prev", that.find(".pxs_prev"));
			that.data("ps.next", that.find(".pxs_next"));
			var id = setInterval(function(){
				if (!that.data("ps.pauseAuto")) {
					that.next();
				}
				if (!that.data("ps.stopAuto")) {
					clearInterval(id);
				}
			}, options.autoScrollTime || 3000);
		});
		return proxied.apply(this, arguments);
	} 
})();

В настройках указываем свойство autoScrollTime (число), равное интервалу между сменой картинок.
Чтобы приостановить автосмену, для элемента, которому вызвали плагин, нужно через data записать правдивое значение в свойство ps.pauseAuto. Чтобы остановить её, присвоить правдивое значение свойству px.stopAuto.
var slider = $(".parallax").parallaxSlider({/*options*/});

// надо бы приостановить его на время
slider.data("ps.pauseAuto", true);

// надоело уже
slider.data("ps.stopAuto", true);

Писалось на коленке... если бы сделали демку этого скрипта в примерочной, можно было бы получше написать.
Ответить с цитированием
  #4 (permalink)  
Старый 13.06.2012, 17:02
Новичок на форуме
Отправить личное сообщение для Gandjubass Посмотреть профиль Найти все сообщения от Gandjubass
 
Регистрация: 13.06.2012
Сообщений: 3

а можно по подробнее)),просто я не очень разбираюсь в скриптах..
www . uyghurstudio . com - тут демо (не реклама)
Ответить с цитированием
  #5 (permalink)  
Старый 13.06.2012, 18:12
sinistral
Посмотреть профиль Найти все сообщения от melky
 
Регистрация: 28.03.2011
Сообщений: 5,418

Что именно Вы не поняли в установке?
Сообщение от Gandjubass Посмотреть сообщение
а можно по подробнее)),просто я не очень разбираюсь в скриптах..
www . uyghurstudio . com - тут демо (не реклама)
Я имел в виду редактируемое демо. Его можно сделать в песочнице.
Ответить с цитированием
Ответ



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

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


Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Прошу помочь. pro100(4eJI) Общие вопросы Javascript 13 02.01.2012 02:55
ВСЕХ ОЧЕНЬ ПРОШУ ПОМОЧЬ ПЛИИИИИЗ HackerSniper Общие вопросы Javascript 9 23.10.2011 22:10
Прошу помочь разобраться с Javascript-ом и т.д. Lucky_ Оффтопик 44 21.07.2010 00:35
прошу помочь найти ошибку в самодельном drag&drop versoul Элементы интерфейса 1 03.03.2010 01:59
Прошу помочь с проверкой формы ввода Гость Общие вопросы Javascript 2 08.03.2008 12:10