onclick hide previous images slowly and show new
up vote
0
down vote
favorite
Is it possible to use this code and first hide old images and show newlike here.I wanted to create a var where I could collect previous images names and probably change timePassed to -timePassed but couldn’t achieve proper effect. If you can, advise, please, pure js.
function animate(draw,duration){
var start = performance.now();
requestAnimationFrame(function animate(time){
var timePassed = time- start;
if(timePassed > duration) timePassed = duration;
draw(timePassed), 1000;
if(timePassed < duration){
requestAnimationFrame(animate);
}
});
}
for(var i=0; i<table.length; i++){
table[i].addEventListener("click", function(event){
clearAll();
var tar = event.target;
targetName=tar.classList;
var name = tar.className;
targetName.add("active");
animate(function(timePassed){
if(tar.className == name +" active"){
head.style.display = "block";
document.querySelector(".maintext").innerHTML=name;
// images appear on the page trough their names
mainIMG.src = name+"1.jpg";
odd1IMG.src = name+"2.jpg";
odd2IMG.src = name+"3.jpg";
}
mainIMG.style.top = timePassed / 3 + "px";
odd1IMG.style.top = timePassed / 3 + "px";
odd2IMG.style.top = timePassed / 3+ "px";
}, 900);
});
}
function clearAll(){
for(var i=0; i<table.length; i++){
table[i].classList.remove("active");
}
}
javascript
add a comment |
up vote
0
down vote
favorite
Is it possible to use this code and first hide old images and show newlike here.I wanted to create a var where I could collect previous images names and probably change timePassed to -timePassed but couldn’t achieve proper effect. If you can, advise, please, pure js.
function animate(draw,duration){
var start = performance.now();
requestAnimationFrame(function animate(time){
var timePassed = time- start;
if(timePassed > duration) timePassed = duration;
draw(timePassed), 1000;
if(timePassed < duration){
requestAnimationFrame(animate);
}
});
}
for(var i=0; i<table.length; i++){
table[i].addEventListener("click", function(event){
clearAll();
var tar = event.target;
targetName=tar.classList;
var name = tar.className;
targetName.add("active");
animate(function(timePassed){
if(tar.className == name +" active"){
head.style.display = "block";
document.querySelector(".maintext").innerHTML=name;
// images appear on the page trough their names
mainIMG.src = name+"1.jpg";
odd1IMG.src = name+"2.jpg";
odd2IMG.src = name+"3.jpg";
}
mainIMG.style.top = timePassed / 3 + "px";
odd1IMG.style.top = timePassed / 3 + "px";
odd2IMG.style.top = timePassed / 3+ "px";
}, 900);
});
}
function clearAll(){
for(var i=0; i<table.length; i++){
table[i].classList.remove("active");
}
}
javascript
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Is it possible to use this code and first hide old images and show newlike here.I wanted to create a var where I could collect previous images names and probably change timePassed to -timePassed but couldn’t achieve proper effect. If you can, advise, please, pure js.
function animate(draw,duration){
var start = performance.now();
requestAnimationFrame(function animate(time){
var timePassed = time- start;
if(timePassed > duration) timePassed = duration;
draw(timePassed), 1000;
if(timePassed < duration){
requestAnimationFrame(animate);
}
});
}
for(var i=0; i<table.length; i++){
table[i].addEventListener("click", function(event){
clearAll();
var tar = event.target;
targetName=tar.classList;
var name = tar.className;
targetName.add("active");
animate(function(timePassed){
if(tar.className == name +" active"){
head.style.display = "block";
document.querySelector(".maintext").innerHTML=name;
// images appear on the page trough their names
mainIMG.src = name+"1.jpg";
odd1IMG.src = name+"2.jpg";
odd2IMG.src = name+"3.jpg";
}
mainIMG.style.top = timePassed / 3 + "px";
odd1IMG.style.top = timePassed / 3 + "px";
odd2IMG.style.top = timePassed / 3+ "px";
}, 900);
});
}
function clearAll(){
for(var i=0; i<table.length; i++){
table[i].classList.remove("active");
}
}
javascript
Is it possible to use this code and first hide old images and show newlike here.I wanted to create a var where I could collect previous images names and probably change timePassed to -timePassed but couldn’t achieve proper effect. If you can, advise, please, pure js.
function animate(draw,duration){
var start = performance.now();
requestAnimationFrame(function animate(time){
var timePassed = time- start;
if(timePassed > duration) timePassed = duration;
draw(timePassed), 1000;
if(timePassed < duration){
requestAnimationFrame(animate);
}
});
}
for(var i=0; i<table.length; i++){
table[i].addEventListener("click", function(event){
clearAll();
var tar = event.target;
targetName=tar.classList;
var name = tar.className;
targetName.add("active");
animate(function(timePassed){
if(tar.className == name +" active"){
head.style.display = "block";
document.querySelector(".maintext").innerHTML=name;
// images appear on the page trough their names
mainIMG.src = name+"1.jpg";
odd1IMG.src = name+"2.jpg";
odd2IMG.src = name+"3.jpg";
}
mainIMG.style.top = timePassed / 3 + "px";
odd1IMG.style.top = timePassed / 3 + "px";
odd2IMG.style.top = timePassed / 3+ "px";
}, 900);
});
}
function clearAll(){
for(var i=0; i<table.length; i++){
table[i].classList.remove("active");
}
}
javascript
javascript
asked yesterday
Sabina
31
31
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53349309%2fonclick-hide-previous-images-slowly-and-show-new%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown