Comments on: Ajax Spy http://jqueryfordesigners.com/ajax-spy/ Tutorials and screencasts Thu, 22 Sep 2011 12:58:42 +0000 hourly 1 http://wordpress.org/?v=3.3.1 By: JohnnyRaw http://jqueryfordesigners.com/ajax-spy/comment-page-1/#comment-7058 JohnnyRaw Mon, 30 Nov 2009 15:28:19 +0000 http://jqueryfordesigners.com/ajax-spy/#comment-7058 <p>Thanks for the great script! It works great though I have one question: As of now, you need to have the HTML ul already populated with existing LI's, plain or pulled out of database through PHP, for example. I'm trying to achieve something slightly different, which is grabbing Twitter/other API's from other site through PHP in an external file. - I don't want to load in this PHP file through phpinclude because that will hog load time on the page for visitors.. so here's what I was trying to do: I tried loading the PHP external file with the .load() function, but then the DOM isn't updated hence this script won't use the newly inserted LI's to do it's magic. </p> <p>Is there any way to solve this problem? </p> <p>much thanks in advance! John</p> Thanks for the great script! It works great though I have one question: As of now, you need to have the HTML ul already populated with existing LI’s, plain or pulled out of database through PHP, for example. I’m trying to achieve something slightly different, which is grabbing Twitter/other API’s from other site through PHP in an external file. – I don’t want to load in this PHP file through phpinclude because that will hog load time on the page for visitors.. so here’s what I was trying to do: I tried loading the PHP external file with the .load() function, but then the DOM isn’t updated hence this script won’t use the newly inserted LI’s to do it’s magic.

Is there any way to solve this problem?

much thanks in advance! John

]]>
By: Paul http://jqueryfordesigners.com/ajax-spy/comment-page-1/#comment-5697 Paul Wed, 09 Sep 2009 22:11:25 +0000 http://jqueryfordesigners.com/ajax-spy/#comment-5697 <p>Does it possible to use it in horizontal version? What i need to change in code for this?</p> <p>With best regards, Paul</p> Does it possible to use it in horizontal version? What i need to change in code for this?

With best regards, Paul

]]>
By: LuK http://jqueryfordesigners.com/ajax-spy/comment-page-1/#comment-5563 LuK Fri, 28 Aug 2009 18:06:53 +0000 http://jqueryfordesigners.com/ajax-spy/#comment-5563 <p>Hi Remy,</p> <p>just wanted to give you some feedback, I tried around the last days to make this work with the spy/scrolling effect and the hoverscroll plugin...and because your code limits the DOM for my purposes I had to switch the code behind the scroller (I needed something that doesn't fade out or remove the items...means if overflow is set to visible on the container, all the items should be displayed)...so I took the new jQuery Tools 1.1 (not yet released) and got it to work, I just don't have the beautiful fading effect anymore (that hurts a little =D) but it does the job it's supposed to...do you really think that is unpractical (understood your last comment a bit like this...)</p> <p>thx anyways for your great work!</p> Hi Remy,

just wanted to give you some feedback, I tried around the last days to make this work with the spy/scrolling effect and the hoverscroll plugin…and because your code limits the DOM for my purposes I had to switch the code behind the scroller (I needed something that doesn’t fade out or remove the items…means if overflow is set to visible on the container, all the items should be displayed)…so I took the new jQuery Tools 1.1 (not yet released) and got it to work, I just don’t have the beautiful fading effect anymore (that hurts a little =D) but it does the job it’s supposed to…do you really think that is unpractical (understood your last comment a bit like this…)

thx anyways for your great work!

]]>
By: Remy http://jqueryfordesigners.com/ajax-spy/comment-page-1/#comment-5408 Remy Thu, 13 Aug 2009 14:25:16 +0000 http://jqueryfordesigners.com/ajax-spy/#comment-5408 <p>@LuK - I think the problem you're trying to solve is a lot harder than you might initially think. The problem is in the UI design, then you can think about what code can solve the problem. </p> <p>I say this because: the spy works by just showing 3 items, when a new item comes in, it fades the last item down, introduces the new item (and then removes the old last item). Therefore, you've only ever got 3 in the DOM.</p> <p>If you don't remove, you still have the problem of the last item being made invisible. So perhaps you can remove the lines of code in the spy that fade the last item down & then remove, but you'd also have to over come the missing scroll bar where the old items overflow (but perhaps you've solved that using the hoverScroll plugin?).</p> <p>I would definitely encourage you to look at the drawing board again. One question that might solve your who issue: does the news come in <em>that</em> frequently that you need a spy? Or equally, do users spend long enough on that page to justify a spy? Or even if it's for aesthetics, as the QuickSnapper one was, is it high enough and focused on the page?</p> <p>If not - I think you should look at removing the spy. I don't mean to discourage, only to keep stuff as simple as possibly when we're working with pretty tricky UIs.</p> <p>Hope that helps.</p> @LuK – I think the problem you’re trying to solve is a lot harder than you might initially think. The problem is in the UI design, then you can think about what code can solve the problem.

I say this because: the spy works by just showing 3 items, when a new item comes in, it fades the last item down, introduces the new item (and then removes the old last item). Therefore, you’ve only ever got 3 in the DOM.

If you don’t remove, you still have the problem of the last item being made invisible. So perhaps you can remove the lines of code in the spy that fade the last item down & then remove, but you’d also have to over come the missing scroll bar where the old items overflow (but perhaps you’ve solved that using the hoverScroll plugin?).

I would definitely encourage you to look at the drawing board again. One question that might solve your who issue: does the news come in that frequently that you need a spy? Or equally, do users spend long enough on that page to justify a spy? Or even if it’s for aesthetics, as the QuickSnapper one was, is it high enough and focused on the page?

If not – I think you should look at removing the spy. I don’t mean to discourage, only to keep stuff as simple as possibly when we’re working with pretty tricky UIs.

Hope that helps.

]]>
By: LuK http://jqueryfordesigners.com/ajax-spy/comment-page-1/#comment-5375 LuK Tue, 11 Aug 2009 03:26:39 +0000 http://jqueryfordesigners.com/ajax-spy/#comment-5375 <p>It's me again, I have it in a way but with some last problem =)...I mixed the two tutorials a bit (just implemented the mouseover stop to the "old" non-ajax spy), it's more or less the same code, just extended with the running variable and the if(running) statement like this:</p> <pre><code>(function ($) { $.fn.simpleSpy = function (limit, interval) { limit = limit || 3; interval = interval || 7000; return this.each(function () { // 1. setup // capture a cache of all the list items // chomp the list down to limit li elements var $list = $(this), running = true, items = [], // uninitialised currentItem = limit, total = 0, // initialise later on height = $list.find('> li:first').height(); // capture the cache $list.find('> li').each(function () { items.push('<li>' + $(this).html() + '</li>'); }); total = items.length; $list.wrap('<div class="spyWrapper" />').parent().css({ height : height * limit }); $list.find('> li').filter(':gt(' + (limit - 1) + ')').remove(); $list.bind('stop', function () { running = false; }).bind('start', function () { running = true; }); // 2. effect function spy() { if (running) { // insert a new item with opacity and height of zero var $insert = $(items[currentItem]).css({ height : 0, opacity : 0, display : 'none' }).prependTo($list); // fade the LAST item out $list.find('> li:last').animate({ opacity : 0}, 1000, function () { // increase the height of the NEW first item $insert.animate({ height : height }, 1000).animate({ opacity : 1 }, 1000); // AND at the same time - decrease the height of the LAST item // $(this).animate({ height : 0 }, 1000, function () { // finally fade the first item in (and we can remove the last) $(this).remove(); // }); }); currentItem++; if (currentItem >= total) { currentItem = 0; } } setTimeout(spy, interval) } spy(); }); }; })(jQuery);</code></pre> <p>and it's initialized with this function:</p> <pre><code>$(function () { $('ul.scroller').simpleSpy().bind('mouseenter', function () { $(this).trigger('stop'); }).bind('mouseleave', function () { $(this).trigger('start'); }); });</code></pre> <p>I combined it with the plugin from here: http://rascarlito.free.fr/hoverscroll/</p> <p>this one is initialized as below (the plugin has to be installed):</p> <pre><code>$('ul.scroller').hoverscroll({ vertical: true, width: 298, height: 330 });</code></pre> <p>you can see a half working example one http://devcfm.031.be/ when you scroll down to the bottom of the page, there is a spy for rss-news (I generate the li's with simple-pie, thus there is already something like your newer version), when you hover it, it stops perfectly and also the scrolling would work, but the problem is, that there are only the 3 displayed newsitems visible, the others are not there somehow and because of that there is not much to scroll =)...so now my question:</p> <p><b>How would I display the whole items.length (all list items visible but because overflow is set to hidden, only three are really visible, the scrolling does the rest) on mouseover?</b></p> <p>could it be something like an else statement after the if(running) statement, such a thing as: else (when the spy is not running) display items.length? How can I achieve that? And how does it get back to "normal" (spy-functionality) after mouseout?</p> <p>thx for any answer!</p> It’s me again, I have it in a way but with some last problem =)…I mixed the two tutorials a bit (just implemented the mouseover stop to the “old” non-ajax spy), it’s more or less the same code, just extended with the running variable and the if(running) statement like this:

(function ($) {

$.fn.simpleSpy = function (limit, interval) {
  limit = limit || 3;
  interval = interval || 7000;

return this.each(function () {
  // 1. setup
    // capture a cache of all the list items
    // chomp the list down to limit li elements
    var $list = $(this),
      running = true,
      items = [], // uninitialised
      currentItem = limit,
      total = 0, // initialise later on
      height = $list.find('> li:first').height();

    // capture the cache
    $list.find('> li').each(function () {
      items.push('<li>' + $(this).html() + '</li>');
    });

    total = items.length;

    $list.wrap('<div class="spyWrapper" />').parent().css({ height : height * limit });

    $list.find('> li').filter(':gt(' + (limit - 1) + ')').remove();

    $list.bind('stop', function () {
      running = false;
    }).bind('start', function () {
      running = true;
    });

    // 2. effect        
    function spy() {
      if (running) {
        // insert a new item with opacity and height of zero
        var $insert = $(items[currentItem]).css({
          height : 0,
          opacity : 0,
          display : 'none'
        }).prependTo($list);

        // fade the LAST item out
        $list.find('> li:last').animate({ opacity : 0}, 1000, function () {
          // increase the height of the NEW first item
          $insert.animate({ height : height }, 1000).animate({ opacity : 1 }, 1000);

          // AND at the same time - decrease the height of the LAST item
          // $(this).animate({ height : 0 }, 1000, function () {
            // finally fade the first item in (and we can remove the last)
            $(this).remove();
          // });
        });

        currentItem++;
        if (currentItem >= total) {
          currentItem = 0;
        }
      }
      setTimeout(spy, interval)
    }

    spy();
});

};

})(jQuery);

and it’s initialized with this function:

$(function () {
  $('ul.scroller').simpleSpy().bind('mouseenter', function () {
    $(this).trigger('stop');
  }).bind('mouseleave', function () {
    $(this).trigger('start');
  });
});

I combined it with the plugin from here: http://rascarlito.free.fr/hoverscroll/

this one is initialized as below (the plugin has to be installed):

$('ul.scroller').hoverscroll({
  vertical: true,
  width: 298,
  height: 330
});

you can see a half working example one http://devcfm.031.be/ when you scroll down to the bottom of the page, there is a spy for rss-news (I generate the li’s with simple-pie, thus there is already something like your newer version), when you hover it, it stops perfectly and also the scrolling would work, but the problem is, that there are only the 3 displayed newsitems visible, the others are not there somehow and because of that there is not much to scroll =)…so now my question:

How would I display the whole items.length (all list items visible but because overflow is set to hidden, only three are really visible, the scrolling does the rest) on mouseover?

could it be something like an else statement after the if(running) statement, such a thing as: else (when the spy is not running) display items.length? How can I achieve that? And how does it get back to “normal” (spy-functionality) after mouseout?

thx for any answer!

]]>
By: LuK http://jqueryfordesigners.com/ajax-spy/comment-page-1/#comment-5358 LuK Sun, 09 Aug 2009 19:04:40 +0000 http://jqueryfordesigners.com/ajax-spy/#comment-5358 <p>Thx 4 that tutorial too, very nice extension of the older version of the spy!!! I have one question: There is the jQuery HoverScroll PlugIn (<a href="http://rascarlito.free.fr/hoverscroll/">http://rascarlito.free.fr/hoverscroll/</a>) which I think is a very useful and nice feature often seen in Flash but I would like to use this with your spy... When I hover the list with the mouse it shouldn't only stop, it should be scrollable up and down, so the user has the choice which item he/she wants to read...I think this would be a nice enhancement and the code is already there...</p> <p>I would just like to know how I can add this effect to your script...would I have to place it in the "if(running)" statement of the script? So in case the spy is not running it activates the hoverscroll-plugin and then on mouseout it gets back to the spy animation?</p> <p>thx 4 your help and keep up the good work!</p> <p>cheers,</p> <p>LuK</p> Thx 4 that tutorial too, very nice extension of the older version of the spy!!! I have one question: There is the jQuery HoverScroll PlugIn (http://rascarlito.free.fr/hoverscroll/) which I think is a very useful and nice feature often seen in Flash but I would like to use this with your spy… When I hover the list with the mouse it shouldn’t only stop, it should be scrollable up and down, so the user has the choice which item he/she wants to read…I think this would be a nice enhancement and the code is already there…

I would just like to know how I can add this effect to your script…would I have to place it in the “if(running)” statement of the script? So in case the spy is not running it activates the hoverscroll-plugin and then on mouseout it gets back to the spy animation?

thx 4 your help and keep up the good work!

cheers,

LuK

]]>
By: jujuwiwi http://jqueryfordesigners.com/ajax-spy/comment-page-1/#comment-5140 jujuwiwi Mon, 13 Jul 2009 19:23:35 +0000 http://jqueryfordesigners.com/ajax-spy/#comment-5140 <p>First thank you for this great tutorial !!!</p> <p>I try to integrate this ajax spy with Wordpress but I need to load ajax-spy-helper.php from an other place than the root (from my theme directory in wordpress)...</p> <p>I try to use a relative path with: $source.load('../ajax-spy-helper.php'); but I can't load the file when I put it on my theme (from the root, no problem but I can't use the worpress functions)...</p> <p>Have you got a clue ?</p> First thank you for this great tutorial !!!

I try to integrate this ajax spy with WordPress but I need to load ajax-spy-helper.php from an other place than the root (from my theme directory in wordpress)…

I try to use a relative path with: $source.load(‘../ajax-spy-helper.php’); but I can’t load the file when I put it on my theme (from the root, no problem but I can’t use the worpress functions)…

Have you got a clue ?

]]>
By: SJ http://jqueryfordesigners.com/ajax-spy/comment-page-1/#comment-5109 SJ Thu, 09 Jul 2009 14:28:16 +0000 http://jqueryfordesigners.com/ajax-spy/#comment-5109 <p>Hi, Thanks for all the great tutorials. I have tried the simple spy and it works fine in firefox and safari. However, the ajax version does not work in firefox. Do I need to do any changes in the code for firefox to accept the ajax?</p> <p>Thanks</p> Hi, Thanks for all the great tutorials. I have tried the simple spy and it works fine in firefox and safari. However, the ajax version does not work in firefox. Do I need to do any changes in the code for firefox to accept the ajax?

Thanks

]]>
By: Selvakumar P http://jqueryfordesigners.com/ajax-spy/comment-page-1/#comment-3258 Selvakumar P Mon, 20 Apr 2009 16:50:20 +0000 http://jqueryfordesigners.com/ajax-spy/#comment-3258 <p>Hi, Really good Job you've done. I just wanted to do like this. If you see here, the list won't get repeated as we have now. Only the new item gets added at the top and there is no duplication or rotation. If there no new item from server, It just stay as it is.</p> <p>http://stocktwits.com/streams/all?popout=true</p> <p>Please help me to do this effect.</p> Hi, Really good Job you’ve done. I just wanted to do like this. If you see here, the list won’t get repeated as we have now. Only the new item gets added at the top and there is no duplication or rotation. If there no new item from server, It just stay as it is.

http://stocktwits.com/streams/all?popout=true

Please help me to do this effect.

]]>
By: nadia http://jqueryfordesigners.com/ajax-spy/comment-page-1/#comment-2524 nadia Mon, 06 Apr 2009 03:40:54 +0000 http://jqueryfordesigners.com/ajax-spy/#comment-2524 <p>Super Cool!</p> <p>I have to update my old code. but do you have option for Play/Stop button?</p> <p>Thanks</p> Super Cool!

I have to update my old code. but do you have option for Play/Stop button?

Thanks

]]>