Javascript.RU

Создать новую тему Ответ
 
Опции темы Искать в теме
  #1 (permalink)  
Старый 01.11.2019, 11:59
Профессор
Отправить личное сообщение для Stas1985 Посмотреть профиль Найти все сообщения от Stas1985
 
Регистрация: 05.03.2012
Сообщений: 159

Пауза при наведении на слайдер
Здравствуйте форумчане!
Столкнулся с такой проблемой. На сайте есть слайдер текста https://lik-astana.kz/ при наведении он не останавливается, должен при наведении остановится чтоб была возможность прочитать текст, как я понимаю в js файле эта функция прописана
/**
* @author    JoomShaper [url]http://www.joomshaper.com[/url]
* @copyright Copyright (C) 2010 - 2013 JoomShaper
* @license   [url]http://www.gnu.org/licenses/gpl-2.0.html[/url] GNU/GPLv2
*/;
(function ($) {
    var methods = {
        currentIndex: 0,
        prevIndex: 0,
        nextIndex: 0,
        totalItems: 0,
        settings: {},
        canvasWidth: 0,
        canvasHeight: 0,
        elements: '',
        prevIndex: function () {
            var c = this.currentIndex;
            c--;
            if (c < 0)
                c = this.totalItems - 1;
            return c;
        },
        nextIndex: function () {
            var c = this.currentIndex;
            c++;
            if (c >= (this.totalItems))
                c = 0;
            return c;
        },

        currentIndex: function () {
            return this.currentIndex;
        },

        prev: function () {
            clearTimeout(this.autoplay);
            this.currentIndex--;
            if (this.currentIndex < 0) {
                this.currentIndex = this.totalItems - 1;
                this.prevIndex = methods['prevIndex'].call(this);
            }
            var $this = this;
            methods['run'].call(this);
        },

        next: function () {
            clearTimeout(this.autoplay);
            this.currentIndex++;
            if (this.currentIndex >=this.totalItems){
                this.currentIndex = 0;
                this.nextIndex = methods['nextIndex'].call(this);
            }
            methods['run'].call(this);
        },

        play: function () {
            var $this = this;
            this.autoplay = setTimeout(function () {
                methods['next'].call($this);
            }, 1000);
        },

        preloader: function () {
            var loadedImage = new Image();
            var preloadImages = this.settings.preloadImages;
            var $this = this;

            if (this.settings.showPreloader != true || preloadImages.length < 1) {
                $(this.settings.preloader).remove();
                methods['start'].call(this);
                this.elements.trigger('onSlide');
            } else {
                for (i = 0; i < preloadImages.length; i++) loadedImage.src = preloadImages[i];
                    $(loadedImage).load(function () {
                        $($this.settings.preloader).fadeOut('fast', function () {
                            $(this).remove();
                        });
                        methods['start'].call($this);
                        $this.elements.trigger('onSlide');
                    });
            }
        },

        autoplay: function () {
            var $this = this;
            if (this.settings.autoplay == true) {
                this.autoplay = setTimeout(function () {
                    methods['next'].call($this);
                }, this.settings.interval);
            }
        },

        pause: function () {
            clearTimeout(this.autoplay);
        },

        goTo: function (index) {
            clearTimeout(this.autoplay);
            if( this.currentIndex==index ){
                return false;
            }
            this.currentIndex = index;
            methods['run'].call(this);
        },

        run: function () {
            clearTimeout(this.delay);
            clearTimeout(this.autoplay);
            var $this = this;
            var $item = this.items;

            $item.each(function(){
                if( $(this).hasClass($this.settings.animateInClass) ){
                    $(this).removeClass($this.settings.animateInClass).addClass($this.settings.animateOutClass);
                }
            });

            this.delay = setTimeout(function () {
                $item.removeClass($this.settings.animateOutClass);
                $item.eq($this.currentIndex).removeClass($this.settings.animateOutClass).addClass($this.settings.animateInClass);

                $this.elements.trigger('onSlide');
            }, this.settings.delay);

            methods['autoplay'].call(this);
        },

        start: function () {
            clearTimeout(this.delay);
            clearTimeout(this.autoplay);
            var $this = this;
            var $item = this.items;

            this.delay = setTimeout(function () {

                $item.eq($this.currentIndex)
                .removeClass($this.settings.animateOutClass)
                .addClass($this.settings.animateInClass);

                $this.elements.trigger('onSlide');
            }, this.settings.delay);

            methods['autoplay'].call(this);
        },

        resize: function (fn) {
            if (this.settings.fullWidth == true) {
                this.elements.height($(window).width() * this.ratioHeight);
            }
        },

        onSlide: function (fn) {
            var $this = this;
            this.elements.bind('onSlide', function (event) {
                fn($this.currentIndex, $this.items, event);
            });
        },

        init: function (elements, settings) {
            this.currentIndex = 0;
            this.elements = elements;
            this.items = $(elements).find('>*');

            this.totalItems = this.items.length;
            this.settings = settings;

            var $this = this;
            this.items.each(function (i) {
                $(this).addClass($this.settings.itemClassPrefix + (i + 1));
            });
        },

    };

    $.fn.spSmartslider = function (options, param) {

        var settings = $.extend({
            preloadImages: [],
            autoplay: true,
            preloader: '.sp-preloader',
            showPreloader: true,
            interval: 5000,
            delay: 500,
            itemClassPrefix: 'item-',
            rWidth: 0,
            rHeight: 0,
            fullWidth: false,
            animateInClass: 'animate-in',
            animateOutClass: 'animate-out',
        }, options);

        return this.each(function (index, element) {

            if (typeof (options) === 'string') {
                methods[options].call(this, param);
            } else {
                methods['init'].call(this, $(this), settings);
                methods['preloader'].call(this);
                methods['autoplay'].call(this);
                methods['resize'].call(this);
            }
        });
    }
})(jQuery);

Пробовал решить средствами css но это не сработало. Подскажите как решить с помощью js.
Спасибо!
Ответить с цитированием
  #2 (permalink)  
Старый 03.11.2019, 19:05
Профессор
Отправить личное сообщение для Stas1985 Посмотреть профиль Найти все сообщения от Stas1985
 
Регистрация: 05.03.2012
Сообщений: 159

Решение так и не нашел, опубликовал как есть https://lik-astana.kz/
Подскажите пожалуйста, почему не работает стандартная пауза при наведении. В js не селен, но думаю что эта функция отвечает за паузу
pause: function () {
	            clearTimeout(this.autoplay);
	        }

Знающие люди, подскажите пожалуйста, в чем проблема и как решить.
Спасибо!
Ответить с цитированием
  #3 (permalink)  
Старый 03.11.2019, 20:26
Аватар для рони
Профессор
Отправить личное сообщение для рони Посмотреть профиль Найти все сообщения от рони
 
Регистрация: 27.05.2010
Сообщений: 33,068

Сообщение от Stas1985
как я понимаю в js файле эта функция прописана
не вижу я в вашем коде паузы при наведении,
функция onhover в вашем коде отсутствует.
Ответить с цитированием
  #4 (permalink)  
Старый 04.11.2019, 12:57
Профессор
Отправить личное сообщение для Stas1985 Посмотреть профиль Найти все сообщения от Stas1985
 
Регистрация: 05.03.2012
Сообщений: 159

Сообщение от рони Посмотреть сообщение
не вижу я в вашем коде паузы при наведении,
функция onhover в вашем коде отсутствует.
Подскажите пожалуйста почему тогда не работает пауза в css
.sp-slider-item:hover {
-webkit-animation-play-state: paused; 
-moz-animation-play-state: paused; 
-o-animation-play-state: paused; 
 animation-play-state: paused; 
}

Может ли данный стиль блокировать/подменять js.
Подскажите пожалуйста какие варианты есть в решении моей проблемы
Ответить с цитированием
  #5 (permalink)  
Старый 04.11.2019, 13:14
Аватар для рони
Профессор
Отправить личное сообщение для рони Посмотреть профиль Найти все сообщения от рони
 
Регистрация: 27.05.2010
Сообщений: 33,068

Stas1985,
js делает паузу и смену картинок, css только эффект смены.
ищите новую версию этого слайдера(ваша 2013, устарела) с onhover.
но она вроде платная.
Ответить с цитированием
  #6 (permalink)  
Старый 04.11.2019, 13:44
Аватар для рони
Профессор
Отправить личное сообщение для рони Посмотреть профиль Найти все сообщения от рони
 
Регистрация: 27.05.2010
Сообщений: 33,068

самый простой слайдер с паузой при наведении
Stas1985,
<!DOCTYPE HTML>
<html>
<head>
  <title>Untitled</title>
  <meta charset="utf-8">
  <style type="text/css">
 .slider li{
   margin: 0px;
   width: 200px; height:50px; float: left;
   display: block;

  }
 .slider .carusel {
    position:relative; top: 0px; left:0px; display:block;
    height:50px;
    padding: 0px; margin: 0px;
  }
  .slider{
     overflow:hidden; width: 200px; height:50px; position: relative;  margin: 100px auto;
  }


 .prev, .next{
    position: absolute;
    width: 20px;
    height: 20px;
    background-color: #DCDCDC;
    top: 10px;
    left: 0;
    border-radius: 50%;
    opacity: .3;
    cursor: pointer;
 }
.next{
  left: 180px;
}
.slider:hover .prev,.slider:hover .next{
  opacity: 1;
}
  </style>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
  <script>

  $(function() {
    var ul = $(".carusel"),
        widthAll = 0,
        loop = true,
        pause = 2000,
        spide = 1200,
        next = false;
    $("li", ul).each(function(indx, element) {
        widthAll += this.offsetWidth
    });
    ul.width(widthAll);

    function go() {
        var li = next ? $("li:last", ul) : $("li:first", ul),
            w = li.width();
        next && (ul.prepend(li).css({
            left: -w
        }), w = 0);
        ul.delay(pause).animate({
            left: -w
        }, spide, function() {
            !next && ul.append(li).css({
                left: 0
            });
            loop && go()
        })
    }
    go();
    $(".slider").on("mouseenter", function() {
        loop = false;
        ul.stop()
    }).on("mouseleave", function() {
        ul.stop();
        loop = true;
        pause = 2000;
        spide = 1200;
        go()
    }).on("click", ".prev, .next", function() {
        pause = 0;
        spide = 800;
        next = $(this).is(".next");
        go()
    })
});

  </script>
</head>

<body>
<div class="slider">
    <ul class="carusel">
            <li  id = "1" style="background-color:red;">1</li>
            <li  id = "2" style="background-color:green;">2</li>
            <li  id = "3" style="background-color:Yellow;">3</li>
            <li  id = "4" style="background-color:DeepPink;">4</li>
            <li  id = "5" style="background-color:MediumBlue;">5</li>
        </ul>
<div class="prev"><</div>
<div class="next">></div>
    </div>
</body>
</html>
Ответить с цитированием
Ответ



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

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


Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Блокировка скролла всей страницы при наведении на элемент TimofeyEid jQuery 2 06.09.2015 14:30
При наведении на определенный блок, DIV, появляется скрытое сожержимое kismedia Элементы интерфейса 9 22.05.2015 19:15
Div при наведении перекрывает меню tart Общие вопросы Javascript 3 18.11.2014 13:40
Смена фона при наведении Crystal Элементы интерфейса 3 13.10.2011 12:23
Менять цвет фона select option при наведении Dmitriykh Элементы интерфейса 3 25.07.2011 13:04