打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
javascript-如何调用jquery插件中的此函数?

我在页面vTicker上使用了一个jquery插件,“用于轻松简单地进行垂直新闻自动滚动”.我将它与rss jquery插件结合使用.它工作正常,但是我需要创建一个可以手动滚动的按钮.谁能告诉我该怎么做?我猜想我需要从vTicker文件中调用moveUp函数,但是由于该函数的创建方式以及vticker本身的创建方式,我不确定该怎么做.

我这样创建我的vTicker:

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

这是vTicker代码:

/** 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);

谢谢阅读.

解决方法:

简短的答案是,你不能. moveUp函数在插件范围内是完全隔离的,您不能直接调用它.

要修改插件,以便您可以手动滚动,请在该行返回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();
来源:https://www.icode9.com/content-1-591901.html
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
jquery无缝向上滚动实现代码
网页特效之下拉菜单
基于jquery的可以拖动的DIV布局插件代码下载
jQuery 插件试手
jQuery Ajax执行顺序问题
jQuery 插件 仿百度搜索框智能提示 调用简单!
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服