开发者

JQuery: How does Gowalla perform it's "slide" effect?

开发者 https://www.devze.com 2022-12-28 04:47 出处:网络
How does Gowalla.com perform it\'s slide effect on the frontpage? What JQuery effect can mimic that functio开发者_如何转开发nality of the sliding down effect?In jQuery, you can just use slideDown to

How does Gowalla.com perform it's slide effect on the frontpage?

What JQuery effect can mimic that functio开发者_如何转开发nality of the sliding down effect?


In jQuery, you can just use slideDown to do something similar, however Gowalla seems to use a slightly different method:

The individual panels are inside a parent panel which periodically changes it position. That is, the panels themselves aren't animating, and nothing is even changing size: it's just moving all the panels through a viewport. When it reaches the bottom, the Gowalla page just stops - it actually loads up enough panels for about 4 minutes of sliding - though in your case, you might want to take panels off the bottom and push them back in the top to make it continuous.


The aptly named slideDown().


I think what they are doing is similar to what nickf mentioned. To create the animation effect, I think all that's done is to animate the position of the div container that wraps around the panels within.

So the parent panel will have a viewport that fits only 6 panels. Another div container will wrap around all the panels. Use jQuery .animate() to shift the div's top position attribute. Each iteration will shift the div container down by a panel's height (e.g. 100px).

var numPanels = 20;
var i = 1;

var livePanel = setInterval(function() {
  if (i < numPanels) {
    $('div.wrap').animate({'top': '+100px'}, 500, 'swing');
    i++;
  } else {
    livePanel.clearInterval();
  }
}, 1000);

That's just a rough code of how I think it could work. You also need to take into account the number of panels that will be in the viewport at any one time, and subtract that from the total number of "shifts down" you'll want, in numPanels.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号