Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7404013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:11:39+00:00 2026-05-29T05:11:39+00:00

I’ve been syncing some text with audio, using jPlayer and jQuery’s .fadeIn/.fadeOut. It works

  • 0

I’ve been syncing some text with audio, using jPlayer and jQuery’s .fadeIn/.fadeOut. It works as expected, using these if statements:

var currentTime = Math.floor(event.jPlayer.status.currentTime)

if (currentTime > 1){
    $("#slide1").fadeIn("fast");             
} else if (currentTime < 1){
    $("#slide1").fadeOut("fast"); 
}

if (currentTime >= 9 && currentTime < 49){
    $("#slide2").fadeIn("fast"); 
} else if (currentTime < 9){
    $("#slide2").fadeOut("fast");   
}

and so on. This will show/hide div’s at the proper time and allow for scrubbing. The code I have adapted is from here. I am a designer who knows a little programming, so my skills aren’t great but I understand a lot. I’m looking for a more efficient way to do this, instead of copy/pasting the if statement as there will be A LOT of them. Possibly an array of all the in/out times? I’m not sure how to do it.

Best case scenario would be to have an xml list of times control prebuilt divs (I think anyway). Any ideas on how to do it?

Thanks for your time,
S

Update

Ok, I’ve made some progress, but am having problems with the XML/loop. I have added content to the XML and have it dynamically generating divs. Here is the xml:

<?xml version="1.0" encoding="utf-8" ?>
<Slides>
<Slide id="#slide1" in="1" out="9999" content="Implications"></Slide>
<Slide id="#slide2" in="9" out="49" content="Implications have the form"></Slide>
<Slide id="#slide3" in="11" out="49" content="If A is true, then B is true."></Slide>
</Slides>

and here is my code that creates the divs (that are hidden)

<script>
var mySlides = [];
$.ajax({
    type: "GET",
    url: "xml.xml",
    dataType: "xml",
    success: parseXml
});
function parseXml(xml)
{
    $(xml).find("Slide").each(function() {
        $("#slides").append("<div class=\"starthidden\" id=" + $(this).attr("id") + ">" + $(this).attr("content") + "</div>");
    });
    var $slides = xml.find('Slide');
    for (var i = 0, len = $slides.length; i < len; i++) {
        mySlides[mySlides.length] = {
            in  : $slides.eq(i).attr('in'),
            out : $slides.eq(i).attr('out')
        };
    }
}
$("#audio").bind($.jPlayer.event.timeupdate, function(event) { 
    var currentTime = Math.floor(event.jPlayer.status.currentTime)
    for (var i = 0; i < len; i++) {
        if (currentTime >= mySlides[i].in && currentTime < mySlides[i].out) {
            $(mySlides[i].id).fadeIn("fast");
        } else if (currentTime < mySlides[i].in) {
            $(mySlides[i].id).fadeOut("fast");
        }
    }   
});
</script>

I guess I just don’t really know where to go from here to get the divs to show/hide now? As well, I’ve got to figure out a way to turn many divs off as well, as slides are actually lines, not full slides so I need to clear them off the stage (if you see in the XML, it would be at 49sec). Can anyone help? Thanks so much.
S

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T05:11:40+00:00Added an answer on May 29, 2026 at 5:11 am

    You can setup an array of objects that store information for each slide.

    //setup an array of objects that store information for each caption
    var mySlides = [
            {
                id  : '#slide1',//set a string reference to the element to fade
                in  : 1,//start time
                out : 9999//end time (this is long so it doesn't fade out ever)
            },
            {
                id  : '#slide2',
                in  : 9,
                out : 49
            }
        ], len = mySlides.length;
    
    //loop through the slides to check if they should be faded in/out
    for (var i = 0; i < len; i++) {
        if (currentTime >= mySlides[i].in && currentTime < mySlides[i].out) {
            $(mySlides[i].id).fadeIn("fast");
        } else if (currentTime < mySlides[i].in) {
            $(mySlides[i].id).fadeOut("fast");
        }
    }
    

    Update

    If your XML file is something like this:

    <slides>
        <slide id="#slide1" in="1" out="9999"></slide>
        <slide id="#slide2" in="9" out="49"></slide>
    </slides>
    

    Then you can grab the XML file using AJAX and parse it for it’s data like this:

    var mySlides = [];
    $.ajax({
        url      : 'path/to/file.xml',
        type     : 'get',
        dataType : 'xml',
        success  : function (serverResponse) {
            var $slides = serverResponse.find('slide');
            for (var i = 0, len = $slides.length; i < len; i++) {
                mySlides[mySlides.length] = {
                    id  : $slides.eq(i).attr('id'),
                    in  : $slides.eq(i).attr('in'),
                    out : $slides.eq(i).attr('out')
                };
            }
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
For some reason, after submitting a string like this Jack’s Spindle from a text
I am reading a book about Javascript and jQuery and using one of the
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.