English 中文(简体)
采用javascript celllus ,通过文字代相传
原标题:Using javascript modulus to iterate through text slider with for loop

我要说的是,我花了新鲜的时间来打ery和 st倒,因此,我试图说出具体的话,但请与我一道。 我试图用模块化,通过清单和重复制作一个案文,其中含有从头脑中的相关链接。

这里的法典Im涉及:

ul#text { position: relative; margin-bottom: 40px; height: 40px; }
ul#text li { position: absolute; display: none; }
.active { font-weight: bold; }
<ul id="text">
<li id="textBody">Suffering is not a result of physical pain alone. It can be compounded by changes in one s life, and changes in the self. <em>We understand, and we can help.</em></li>
<li id="textFamily">Aggressive assessment of physical symptoms &amp; pain in the body are key to support <em>the best possible quality of life</em>.</li>
<li id="textFunction">Chronic pain &amp; illness may affect your role in your family. We work with you and your family as you confront those changes.</li>
<li id="textPsyche">Chronic pain and illness make even everyday activities challenging. We will help you maintain independence and physical function.</li>
<li id="textSuffering">Changes in the physical body mean changes in the self. We will provide support as you navigate those changes in the psyche.</li>
</ul>
<ul id="vivid_buttons">
<li><a href="#" id="buttonBody">BODY</a></li>
<li><a href="#" id="buttonFamily" class="active">FAMILY</a></li>
<li><a href="#" id="buttonFunction">FUNCTION</a></li>
<li><a href="#" id="buttonPsyche">PSYCHE</a></li>
<li><a href="#" id="buttonSuffering">SUFFERING</a></li>
</ul>
$(document).ready(function () {

    function fadeAndMove() {
        var nextLi = $("#text > li:nth-child(" + i % 5 + ")");
        var nextA = $("#vivid_buttons > li:nth-child(" + i % 5 + ") > a");
        nextLi.fadeIn(1000, function () {
            $("#vivid_buttons > li > a").removeClass("active");
            nextA.addClass("active");
            setTimeout(function () {
                nextLi.fadeOut(1000);
            }, 4000);
        });
    }

    for (i = 1; i < 7; i++) {
        fadeAndMove($("#text"));
    }
});

简言之,我想从第一个名单上删除一句,并强调下个名单上的相应联系。 然后,我想谈谈下一个项目。

我认为,我可以使用组合((%),并 lo,通过和创造无限的住所,但当我这样认为,它一劳永逸地执行所有事情时,就不通过(穿透和排出)每个项目。

我知道这一点令人困惑,但我不胜感激我能得到的任何帮助。

问题回答

查阅<><>t>for loop>的<代码>,并且通过现行索引,仅使用“fadeAndMove(<>的功能”。

http://jsfiddle.net/drWhE/。

$(document).ready(function () {

       // cache the LI elements
    var $lis = $("#text > li");
    var $aLis = $("#vivid_buttons > li");

    function fadeAndMove( currentIndex ) {
        var nextIndex = (currentIndex + 1) % 5;
        var nextLi = $lis.eq( nextIndex );
        nextLi.fadeIn(1000, function () {
            $aLis.eq( currentIndex ).children( a ).removeClass("active");
            $aLis.eq( nextIndex ).children( a ).addClass("active");
            setTimeout(function () {
                nextLi.fadeOut(1000, function() {
                      // Call fadeAndMove() passing nextIndex as the new currentIndex
                    fadeAndMove( nextIndex );
                });
            }, 4000);
        });
    }
       // Get it started on index 0
    fadeAndMove( 0 );
});

由于你的主要休息时间为 keeps su<>m>,而你们的离去时间为4秒。

顺理成章的是,它就象这样(每一行代表了第二行):

li1.fadeIn
li2.fadeIn  |
li3.fadeIn  | |
li4.fadeIn  | | |      Timers
li5.fadeIn  V | | |    wait four
li1.fadeOut   V | | |  seconds
li2.fadeOut     V | |
li3.fadeOut       V |
li4.fadeOut         V
li5.fadeOut
li1.fadeIn
li2.fadeIn
.
.
.
etc, etc, ad nauseam.

为了解决这个问题,你需要在你延迟的职能中排除目前项目之后,将次电话链到fadeAndMove():

nextLi.fadeIn(1000, function () {
    $("#vivid_buttons > li > a").removeClass("active");
    nextA.addClass("active");
    setTimeout(function () {
        nextLi.fadeOut(1000);
        fadeAndMove(i + 1);
    }, 4000);
});

(由于这一呼吁被拖延,它没有休养。) 独一无二的争 lo赢得了 t。

这里是获得你重新研究的一个途径:

var $sentence_set = $( ul#text > li );
var $link_set = $( ul#vivid_buttons > li );

var highlight = function(which) {
  var el = $sentence_set.eq(which - 1);
  var position = el.prevAll( li ).length;
  $link_set.removeClass( active ).eq(position).addClass( active );
  $sentence_set.eq(position).siblings().fadeOut().end().fadeIn();
}

var loopcount = 0;
var repeater = setInterval(function() {
  var theList = $( #text > li );
  highlight(++loopcount % $sentence_set.length);
}, 4000);​

http://jsfiddle.net/dk43R/“rel=“nofollow”>。

并且...... o吧告诉我,小小小小小.子对我说的是类似的东西。 确实,这是一条路。





相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...