How can I call this function inside jquery plugin?

I use the jquery plugin on my page, vTicker , "for quick and easy vertical automatic news scrolling." I use it in conjunction with the rss jquery plugin. It works fine, but I need to create a button that will execute a manual scroll. Can someone tell me how to do this? I assume that I need to call the moveUp function from the vTicker file, but because of how the function is created and how vticker is created, I'm not quite sure how to do this.

I create my vTicker as follows:

$('#ticker1').rssfeed(uRL).ajaxStop(function() {
$('#ticker1 div.rssBody').vTicker();
})

And here is the vTicker code:

/*
* Tadas Juozapaitis ( kasp3rito@gmail.com )
*/
(function($){
$.fn.vTicker = function(options) {
    var defaults = {
        speed: 700,
        pause: 15000,
        showItems: 3,
        animation: '',
        mousePause: true,
        isPaused: false
    };

    var options = $.extend(defaults, options);


    moveUp = function(obj2, height){


        if(options.isPaused)
            return;

        var obj = obj2.children('ul');

        var iframe = $('#iFrame2');


        first = obj.children('li:first').clone(true);
        second = obj.children('li:odd:first').clone(true);

        iframe.attr('src', (second.children('h4').children('a').attr("href")));


        obj.animate({top: '-=' + height + 'px'}, options.speed, function() {
            $(this).children('li:first').remove();
            $(this).css('top', '0px');
        });

        if(options.animation == 'fade')
        {
            obj.children('li:first').fadeOut(options.speed);
            obj.children('li:last').hide().fadeIn(options.speed);
        }

        first.appendTo(obj);
    };

    return this.each(function() {
        var obj = $(this);
        var maxHeight = 0;

        obj.css({overflow: 'hidden', position: 'relative'})
            .children('ul').css({position: 'absolute', margin: 0, padding: 0})
            .children('li').css({margin: 0, padding: 0});

        obj.children('ul').children('li').each(function(){
            if($(this).height() > maxHeight)
            {
                maxHeight = $(this).height();
            }
        });

        obj.children('ul').children('li').each(function(){
            $(this).height(maxHeight);
        });

        obj.height(maxHeight * options.showItems);

        var interval = setInterval(function(){ moveUp(obj, maxHeight); }, options.pause);

        if(options.mousePause)
        {
            obj.bind("mouseenter",function(){
                options.isPaused = true;
            }).bind("mouseleave",function(){
                options.isPaused = false;
            });
        }
    });
};
})(jQuery);

Thanks for reading.

+3
source share
2

: . moveUp , .

, , return this.each(function() {:

$.fn.extend({
  vTickerMoveUp: function() {
    var obj = $(this);
    var maxHeight = 0;
    obj.children('ul').children('li').each(function(){
        if($(this).height() > maxHeight) maxHeight = $(this).height();
    });
    moveUp(obj, maxHeight);
  }
});

, , :

var ticker = $('#ticker1 div.rssBody').vTicker();
ticker.vTickerMoveUp();
+3

moveup var, , moveup() ( ) vTicker. , , moveup() .

0

Source: https://habr.com/ru/post/1754341/


All Articles