Added Background Not Working
May 12, 2018
Hi Folks,
I am developing a course which has Javascripts included on every single slide. I have taken a Javascript for fetch a current time and date almost 60% slide. And other than that taken a Javascript for a every slide it has mentioned the Background Javascript.
Here is the problem: If I am using only same Background change Javascript in few slides it perfectly works. When it come to multiple Javascript or multiple times of same Javascripts. It doesn't work even I tried using Javascript in master slide. Still it is showing multiple copies in User.js
Here is the Javascripts which I am using in course.
Date and Time: Execute Javascript on timeline start
ar currentDate = new Date()
var day = currentDate.getDate()
var month = currentDate.getMonth() + 1
var year = currentDate.getFullYear();
var player = GetPlayer();
var newName = day + "/" + month + "/" +year
player.SetVar("DateValue", newName);
var currentTime = new Date()
var hours = currentTime.getHours()
var minutes = currentTime.getMinutes()
if (minutes
minutes = "0" + minutes
var suffix = "AM";
if (hours >= 12) {
suffix = "PM";
hours = hours - 12;
}
if (hours == 0) {
hours = 12;
}
var CurTime = hours + ":" + minutes + " " + suffix ;
player.SetVar("TimeValue",CurTime);
For Background Change:
document.body.style.backgroundImage = "url('img_tree.jpg')";
Can anyone help me to slove this problem.
Pravin Dixit
3 Replies
I have removed Javascript from master slide and only added on few pages where required. Still I am facing same problem.
Hi Matthew,
Finally It is working fine, I am writing process here so if anyone required they can use it.
Step1: Add Trigger Execute Javascript when timeline start
Javascript:
document.body.style.backgroundImage = "url('BG.jpg')";
document.body.style.backgroundSize = "cover";
document.body.style.backgroundRepeat = "no-repeat";
document.body.style.overflow = "hidden";
Step2: Rename your image to BG.jpg
Step3: Publish package and place your BG.jpg in the output folder.
Done, now run and check your output.
For current Date and Time.
Step1: Add Trigger Execute Javascript when timeline start
Javascript
var currentDate = new Date()
var day = currentDate.getDate()
var month = currentDate.getMonth() + 1
var year = currentDate.getFullYear();
var player = GetPlayer();
var newName = month + "/" + day + "/" +year
player.SetVar("DateValue", newName);
var currentTime = new Date()
var hours = currentTime.getHours()
var minutes = currentTime.getMinutes()
var seconds = currentTime.getSeconds()
if (hours <12)
var suffix = "AM";
if (hours >= 12)
var suffix = "PM";
var CurTime = hours+":"+minutes+":"+seconds+" "+suffix;
player.SetVar("TimeValue",CurTime);
Step2: Create two variable in storyline
1. TimeValue
2.DateValue
Step3: Add both variables on screen with the help of text box.
%DateValue%
%TimeValue%
Now, Publish your course you will able to see current Date and Time of your computer.
This discussion is closed. You can start a new discussion or contact Articulate Support.