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 7955775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T03:47:39+00:00 2026-06-04T03:47:39+00:00

I’m using the wonderful reveal.js library to create a HTML slideshow. My only problem

  • 0

I’m using the wonderful reveal.js library to create a HTML slideshow. My only problem is that I need it to synchronise across multiple devices.

At the moment I am making a AJAX request to the the time from the server and keep an internal clock for the page.

function syncTime() {
    // Set up our time object, synced by the HTTP DATE header
    // Fetch the page over JS to get just the headers
    console.log("syncing time")
    var r = new XMLHttpRequest();
    r.open('HEAD', document.location, false);
    r.send(null);
    var timestring = r.getResponseHeader("DATE");

    systemtime = new Date(timestring); // Set the time to the date sent from the server
}

Whilst this gets me within 1 or so seconds of accuracy, I need to do better. The difference is really noticeable when the slideshow is auto advancing.

The code is going to be running all on the same platform, so cross-browser compatibility is nothing to worry about.

Here’s what I’ve managed to put together

Any ideas?

  • 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-06-04T03:47:41+00:00Added an answer on June 4, 2026 at 3:47 am

    How about a different approach: who cares about time? (You’re not going to reliably sync the system clock with JavaScript.)

    Instead, use a Node server with socket.io to synchronize when your clients advance the slideshow. Instead of the clients deciding when to advance, the server tells them to.

    This approach comes with the added bonus of being able to manually fiddle with the slideshow while it’s running. In the example that follows, I’ve added a Next button that causes all connected clients to immediately advance to the next slide.

    app.js

    var express = require('express')
        , app = express.createServer()
        , io = require('socket.io').listen(app)
        , doT = require('dot')
        , slide = 0
        , slides = [
            'http://placekitten.com/700/400?image=13',
            'http://placekitten.com/700/400?image=14',
            'http://placekitten.com/700/400?image=15',
            'http://placekitten.com/700/400?image=16',
            'http://placekitten.com/700/400?image=1',
            'http://placekitten.com/700/400?image=2',
            'http://placekitten.com/700/400?image=3',
            'http://placekitten.com/700/400?image=4',
            'http://placekitten.com/700/400?image=5',
            'http://placekitten.com/700/400?image=6',
            'http://placekitten.com/700/400?image=7',
            'http://placekitten.com/700/400?image=8',
            'http://placekitten.com/700/400?image=9',
            'http://placekitten.com/700/400?image=10',
            'http://placekitten.com/700/400?image=11',
            'http://placekitten.com/700/400?image=12',
        ];
    
    app.listen(70); // listen on port 70
    
    app.register('.html', doT); // use doT to render templates
    app.set('view options', {layout:false}); // keep it simple
    doT.templateSettings.strip=false; // don't strip line endings from template file
    
    app.get('/', function(req, res) {
        res.render('index.html', { slide: slide, slides: slides });
    });
    
    app.post('/next', function(req, res) {
        next();
        res.send(204); // No Content
    });
    
    setInterval(next, 4000); // advance slides every 4 seconds
    
    function next() {
        if (++slide >= slides.length) slide = 0;
        io.sockets.emit('slide', slide);
    }
    

    views/index.html

    This file is processed as a doT template.

    <!DOCTYPE html>
    <html>
    <head>
    <title>Synchronized Slideshow</title>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
    <script src="/socket.io/socket.io.js"></script>
    <script>
    var curslide = {{=it.slide}}; // the slide the server is currently on.
    
    $(function() {
        $('#slide' + curslide).css('left',0);
    
        $('#next').click(function() {
            $.post('/next');
        });
    });
    
    var socket = io.connect('http://localhost:70');
    socket.on('slide', function(slide) {
        $('#slide' + curslide).animate({left:-700}, 400);
        $('#slide' + slide).css('left',700).show().animate({left:0}, 400);
        curslide = slide;
    });
    </script>
    <style>
    #slideshow, .slide { width:700px; height:400px; overflow:hidden; position:relative; }
    .slide { position:absolute; top:0px; left:700px; }
    </style>
    </head>
    <body>
        <div id="slideshow">
            {{~it.slides :url:i}}
                <div id="slide{{=i}}" class="slide"><img src="{{=url}}"></div>
            {{~}}
        </div>
        <button id="next">Next &gt;</button>
    </body>
    </html>
    

    Copy these two files into a folder, then run

    $ npm install express socket.io dot
    $ node app.js
    

    and navigate to http://localhost:70 in several different windows, then see the magic.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have thousands of HTML files to process using Groovy/Java and I need to
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

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.