SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2009
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Why won't this bit of code work?

    <script type="text/javascript">



    if (document.all || document.getElementById){ //if IE4 or NS6+

    &nbsp;document.write('<style type="text/css">\n');

    &nbsp;document.write('.dyncontent{display: none; width: 250px; height:
    60px;}\n');

    &nbsp;document.write('</style>');

    }



    var curcontentindex=0;

    var messages=new Array();



    function getElementByClass(classname){

    &nbsp;var inc=0;

    &nbsp;var alltags=document.all? document.all :
    document.getElementsByTagName("*");

    &nbsp;for (i=0; i<alltags.length; i++){

    &nbsp; &nbsp;if (alltags[i].className==classname)

    &nbsp; &nbsp; &nbsp;messages[inc++]=alltags[i];

    &nbsp;}

    }



    function rotatecontent(){

    &nbsp;//get current message index (to show it):

    &nbsp;curcontentindex=(curcontentindex<messages.length-1)?
    curcontentindex+1 : 0;

    &nbsp;//get previous message index (to hide it):

    &nbsp;prevcontentindex=(curcontentindex==0)? messages.length-1 :
    curcontentindex-1;

    &nbsp;messages[prevcontentindex].style.display="none"; //hide previous
    message

    &nbsp;messages[curcontentindex].style.display="block"; //show current
    message

    }



    window.onload=function(){

    &nbsp;if (document.all || document.getElementById){

    &nbsp; &nbsp;getElementByClass("dyncontent");

    &nbsp; &nbsp;setInterval("rotatecontent()", 2000);

    &nbsp;}

    }



    </script>



    Dynamic Content:

    <div class="dyncontent" style="display: block"><a href="http://fithope.com/2010/02/22/health-discussion.aspx">1</div>

    <div class="dyncontent"><a href="http://fithope.com/2010/02/22/health-discussion.aspx">2</div>

    <div class="dyncontent"><a href="http://fithope.com/2010/02/22/health-discussion.aspx">3</div>

    <div class="dyncontent" style="display: block"><a href="http://fithope.com/2010/02/22/health-discussion.aspx">3</div>

    <div class="dyncontent"><a href="http://fithope.com/2010/02/22/health-discussion.aspx">2</div>

    <div class="dyncontent"><a href="http://fithope.com/2010/02/22/health-discussion.aspx">1</div>

    If you have time that is. I don't understand what's wrong with it. I'm trying to figure out a way to make a content slider that slides posts and holds 3 of them at a time.

    I'm trying to get the thing at the top of techcrunch.com that holds 3 posts.

  2. #2
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can't have &nbsp; HTML entity references inside your JavaScript code.
    Birnam wood is come to Dunsinane

  3. #3
    SitePoint Enthusiast
    Join Date
    Aug 2009
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh damn. My editor did that. thanks.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •