推子 Ticker JQuery 和 PHP

发布于 2024-11-07 05:30:29 字数 630 浏览 0 评论 0原文

我编写的这个(可爱的)小脚本应该轻轻地淡出列表中的每个元素

  • 。但什么也没发生。怎么了。

    <div id="twitnews" style="padding-left:20px; line-height:20px; float:left;">
            <?php getFeed("http://search.twitter.com/search.rss?q=golf+berkshire"); ?>
        </div>
    
    <script type="text/javascript">
    function fader() {
    
    $(element).fadeIn(300, function(){
        $(element).delay(3000).fadeOut(300) });
    
            var element = $(element).next();
    
            fader();
    
    }
    $('#twitnews').children().hide();
    
    var element = $('#twitnews').children().first();
    fader();
            </script>
    

    任何想法,

    太棒了

    This (lovely) little script I wrote should gently fade through each element in a list <li></li>. But nothing happens at all. What's wrong.

    <div id="twitnews" style="padding-left:20px; line-height:20px; float:left;">
            <?php getFeed("http://search.twitter.com/search.rss?q=golf+berkshire"); ?>
        </div>
    
    <script type="text/javascript">
    function fader() {
    
    $(element).fadeIn(300, function(){
        $(element).delay(3000).fadeOut(300) });
    
            var element = $(element).next();
    
            fader();
    
    }
    $('#twitnews').children().hide();
    
    var element = $('#twitnews').children().first();
    fader();
            </script>
    

    Any ideas,

    Marvellous

    如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

    扫码二维码加入Web技术交流群

    发布评论

    需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

    评论(4

    幽蝶幻影 2024-11-14 05:30:30

    原始代码中有很多错误,选择器不正确,全局变量没有正确使用,这对于插件演示来说是完美的。

    (function($){
    // Make it a plugin
    $.fn.twicker = function(settings) {
      // Default Variables
      var c = {time: 1300};
      // Override the variables with the settings if available.
      $.extend(c, settings);
      var $t = $(this);
      // If we find a ul, means we passed the container (a div that contains a ul)
      if($('ul', $t).length == 1) {
          $tw = $t;
          $t = $('li', $t).first();
      }
    
      // Do the animation.
      $t.delay(c.time).fadeIn(c.time, function() {
        // If there's a next sibling, do next.
        if($t.next().length != 0) {
            $t.next().twicker();
            $t.next().fadeOut();
    
        // If there's no sibling, it means we're at the end. Go back to first.
        } else {
            $tw.first().twicker();
            $t.first().fadeOut();
        }
        $t.fadeOut(c.time);
      });
    
    };
    
    })(jQuery);
    
    $('#twitnews').twicker({time:2000});
    

    您可以在 JSFiddle 上观看此直播

    There are many errors in the original code, selectors were incorrect, global variables are not used correctly and this is perfect for a plugin demonstration.

    (function($){
    // Make it a plugin
    $.fn.twicker = function(settings) {
      // Default Variables
      var c = {time: 1300};
      // Override the variables with the settings if available.
      $.extend(c, settings);
      var $t = $(this);
      // If we find a ul, means we passed the container (a div that contains a ul)
      if($('ul', $t).length == 1) {
          $tw = $t;
          $t = $('li', $t).first();
      }
    
      // Do the animation.
      $t.delay(c.time).fadeIn(c.time, function() {
        // If there's a next sibling, do next.
        if($t.next().length != 0) {
            $t.next().twicker();
            $t.next().fadeOut();
    
        // If there's no sibling, it means we're at the end. Go back to first.
        } else {
            $tw.first().twicker();
            $t.first().fadeOut();
        }
        $t.fadeOut(c.time);
      });
    
    };
    
    })(jQuery);
    
    $('#twitnews').twicker({time:2000});
    

    You can view this live on JSFiddle

    耶耶耶 2024-11-14 05:30:30

    尝试将 element 传递给 fader()

    fader(element);
    

    在脚本的末尾。

    定义 fader() 时还要包含 element

    function fader(element){
        //the rest of your function code here
    }
    

    Try passing element to fader().

    fader(element);
    

    at the end of your script.

    Also include element when you define fader()

    function fader(element){
        //the rest of your function code here
    }
    
    可是我不能没有你 2024-11-14 05:30:30

    我不知道为什么你的脚本不起作用,但我建议你采取一些不同的方法。将所有 JS 代码替换为:

    $('#twitnews').children().each(function(){
      $(this).fadeIn(300, function() {
        $(this).delay(3000).fadeOut(300);
      });
    });
    

    注意:我只是重新排列了您的代码以消除全局变量、奇怪的元素遍历和递归调用。我没有触及动画 - 但您应该能够使用新代码轻松找到错误。

    I have no idea why your script doesn't work, but I suggest you take a little different approach. Replace all your JS code with:

    $('#twitnews').children().each(function(){
      $(this).fadeIn(300, function() {
        $(this).delay(3000).fadeOut(300);
      });
    });
    

    Note: I have only rearranged your code to get rid of global vars, weird element traversing and recursive calls. I did not touch the animation - but you should be able to find the bugs very easily with the new code.

    情栀口红 2024-11-14 05:30:30

    我认为这是一个非常简单的解决方案。唯一的问题是使用 if 函数来确定这是否是最后一个 li 是不起作用的。也许有人知道它出了什么问题。

     $('#twitnews li').hide();
        $('#twitnews li').first().fadeIn(300, function fade(){
    
            var visel = $('#twitnews li:visible');
    
            if((visel).is($('#twitnews li:last'))) {
                var nextel =  $('#twitnews li').first();
            }
            else {
            var nextel = $(visel).next();
            }
    
    
            $(visel).delay(3000).fadeOut(300, function(){
    
                $(nextel).fadeIn(300, function(){fade()});
    
                });
    
            });
    

    I think this is a very simple solution. The only problem is the use of the if function to determine if this is the last li is non functional. Perhaps someone knows what's wrong with it.

     $('#twitnews li').hide();
        $('#twitnews li').first().fadeIn(300, function fade(){
    
            var visel = $('#twitnews li:visible');
    
            if((visel).is($('#twitnews li:last'))) {
                var nextel =  $('#twitnews li').first();
            }
            else {
            var nextel = $(visel).next();
            }
    
    
            $(visel).delay(3000).fadeOut(300, function(){
    
                $(nextel).fadeIn(300, function(){fade()});
    
                });
    
            });
    
    ~没有更多了~
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文