1

我正在使用 jQuery ScrolTO 插件:http ://demos.flesler.com/jquery/scrollTo/在这个站点:www.imfrom.me

我有向上和向下导航的箭头,到目前为止我正在使用:

    $('.down_stream').click(function(){
        $.scrollTo( '#stream', 1500, {easing:'easeOutElastic'} );       
    });

因此,单击 .down_stream 转到#stream,也就是向下箭头,带您进行流式传输。我一直在尝试阅读并找出一个 jQuery 选择器来处理它以移动到 NEXT 段,而无需复制/粘贴该片段 15 次以上进行上下移动。

我什么都想不通。每个段都包含在此块中:

<div id="stream" class="box">
        <div class="grid_12 arrow up_home">
            &uarr;
        </div>
        <div class="grid_2"><div class="number-heading">01.</div></div>
        <div class="grid_10">
            <h2 class="content_title">what's been new?</h2>

            <p>Blah blah blah blah...</p>
        </div>
        <div class="grid_12 arrow down_about">
            &darr;
        </div>
    </div><!-- end strean -->
4

1 回答 1

0

Not a jQuery expert, but I'll give it a stab. If I understand properly, it's the '#stream' part that has to change each time you click the up/down arrow. So each div will have a different id and you need to feed those to this little snippet to get it to scroll?

Use an array and an integer var to keep track of which way to move in the array.

//initialize the array w/ your 15 div names
var divNames = ["#stream", "#nextDivName", "#andTheNext", "#yetAnotherDivName"];

var index = 0;

function moveUp()
{
  if((index - 1) >= 0){index--;}
  move(index);
}
function moveDown()
{
  if((index + 1) < (divNames.length)){index++;}
  move(index);
}
function move(p_Index)
{
   $.scrollTo( divNames[p_Index], 1500, {easing:'easeOutElastic'} );
}

Button clicks now call the moveUp() & moveDown() functions.

Hope that helps.

于 2009-07-09T01:29:40.107 回答