Change image src with jquery for 5 seconds [closed] - javascript

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
I need help with how to change an image src with another one for 5 seconds before reverting back to the default one with jquery.
below is a code I am trying to use.
$('#indicator').attr("src", 'notification.png');
I need to change it for 5 seconds only.

You need just two scripts
$('#indicator').attr("src", 'notification-new.png');
and
setTimeout(function(){ $('#indicator').attr("src", 'notification.png'); }, 5000);
The first one changes the attribute to a new src and the second one changes it back to the original state after 5 seconds.

var oldSrc = $('#indicator').attr("src"); //save old image source
$('#indicator').attr("src", 'notification.png'); //set new image source
setTimeout(function(){ $('#indicator').attr("src", oldSrc); }, 5000); // after 5 seconds, reset old image source

var changeSrc = function(obj){
var elem = jQuery(obj.selector), img = elem.attr('src'); elem.attr('src', obj.tmpSrc);
setTimeout(function(){elem.attr('src', img);}, 1000*obj.revertAfter);
};
changeSrc({
selector: 'your-img-selector-here',
tmpSrc: 'your-tmp-img-src-here',
revertAfter: 5
});

Related

why the setInterval method gets 10 as input variable? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
my stopwatch with javascript and I don't get this point
buttonStart.addEventListener("click", () => {
if (Interval) {
clearInterval(Interval); }
Interval = setInterval(startTimer, 10); });
The second value it receives is the number of milliseconds between repetitions. Meaning each 10 milliseconds it will run the startTimer function.

How to set interval (time) of to execute javascript code? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I need to set interval in javascript.
I currently have javascript code whose execution is delayed, I need that code to be executed every x seconds. Is there any way to do that?
var delayInMilliseconds = 3000; //1 second
setTimeout(function() {
//MY CODE HERE
}, delayInMilliseconds);
Thank you
You want to use setInterval. It will execute the function every x milliseconds.
const delayInMilliseconds = 3000;
setInterval(() => {
// Your code here
}, delayInMilliseconds);
you can use setInterval() function:
var delayInMilliseconds = 3000; //1 second
setInterval(function() {
// do stuff
}, delayInMilliseconds);

Change inner html every x seconds [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
how to change itens in a table with javascript, every 15 seconds using uinnerHTML:
document.getElementById("iten1").innerHTML = "Bla Bla Bla";
You can create a recursive timeout loop.
function timeout() {
setTimeout(function () {
// Do Something Here
// Then recall the parent function to
// create a recursive loop.
timeout();
}, 1000);
}
If you're new to setTimeout() MDN has a pretty straightforward guide you can play around with. : setTimeout MDN

How to get hold of a part of dynamically generated URL [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I'm using filestack, when ever I upload an image it creates an unique url for the uploaded Image. I want to get hold of a specific part of a url to a variable.
https://www.filestackapi.com/api/file/qiXTZ0dQUGPQRG4GH0Cy
https://www.filestackapi.com/api/file/"qiXTZ0dQUGPQRG4GH0Cy"
The above Url belongs to an image, but I want get hold of the quoted part to a variable, how to do that?
You can search for the last index of / in the url then make a substring of the url starting from that point.
var url = 'https://www.filestackapi.com/api/file/qiXTZ0dQUGPQRG4GH0Cy';
var lastIndex = url.lastIndexOf("/");
var searched = url.substring(lastIndex + 1);
// searched = qiXTZ0dQUGPQRG4GH0Cy

How to save a variable javascript? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
So im running this script and i want to be able to save the variable stopNumber after the script is finished running so that the next time i run this script the saved variable stopNumber can be set to the variable loops so that i dont have to manually set it all the time.
var loops = Number(prompt("Starting csv line?"));
var stopNumber = loops + 15;
for (csvLine = loops ; csvLine <= stopNumber ; csvLine++) {
iimSet ("-var_CSVLINE", csvLine);
iimPlay("Testing.iim");
}
You can store the value in local storage
localStorage.setItem("stopNumber", stopNumber);
Retrieve it with
stopNumber = parseInt(localStorage.getItem("stopNumber"));
More info here
http://www.w3schools.com/html/html5_webstorage.asp
try to use localStorage.
Like:
localStorage.stopNumber = stopNumber;
you may call it as localStorage.stopNumber

Categories

Resources