setinterval

setinterval says not defined function but it is

好久不见. 提交于 2019-12-02 09:52:49
问题 i have this function which i define inside HEAD: <script type="text/javascript" src="http://code.jquery.com/jquery-1.11.1.min.js"> function live() { $.get("http://mydomain.com/script.php", function(data){ var timer = data; var elm = document.getElementById("live"); if (timer == 1){ elm.style.display = 'block'; } else{ elm.style.display = 'none'; } }); } </script> and then i do a loop like this at the very end of my document: <script type="text/javascript"> setInterval(live,10000); </script>

How to pause and resume jquery interval

送分小仙女□ 提交于 2019-12-02 09:45:31
I have made a custom slider with jQuery. For this I have used setInterval function: timer = setInterval(function() {}, 8000); But I cannot pause and resume the interval. I have 2 buttons (play, pause) which I want to use for. Lets say I click pause after 3 sec, and then resume it. So it should stay in that slider for 5 more seconds and then go to the next one and continue 8 seconds each. I have seen this kinda slider with mouseover pause, but can't do it by myself. I have tried this: clearInterval(timer); But this seems reset the interval, don't pause. Can anyone help :) I'm not entirely sure

how to animate a bouncing ball on canvas

孤街醉人 提交于 2019-12-02 09:30:08
问题 Hi I've just started coding Java and HTML, etc, so I tend to struggle at times. Hence I have joined StackOverflow for your help (Be nice to me please :) ) I'm trying to animate using setInterval() and draw method to create a bouncing ball which moves by a number of pixels in each frame. When it hits an edge it should bounce back by reversing the direction of the relevant horizontal or vertical pixel velocity. Here is what has been done so far, my HTML code: <!DOCTYPE html> <html lang="en">

setInterval does not seem to be working?

限于喜欢 提交于 2019-12-02 09:27:39
This code does not seem to be working. I am trying to create a dynamic list of chat rooms available that updates every 10 seconds. I also want the user to be able to set peraminters to filter what rooms would be shown. I am using this code, and it does not seem to be working for some reason. <script type="text/javascript"> function setRooms() { console.log('ok'); if($('#only').is(':checked')) { var checked = 1; } else { var checked = 0; } if($('#open').is(':checked')) { var opened = 1; } else { var opened = 0; } $.post('backend/outputRooms', { fLevel : $('#flevel').val(), sLevel : $('#slevel')

Javascript setInterval works but not infinite loop

为君一笑 提交于 2019-12-02 07:49:29
问题 I don't understand why the infinite loop does not work but uncommenting the function call works. <body> <canvas id="myCanvas"style="border:2px solid black;" width="1600" height="900"> Your browser does not support the HTML5 canvas tag. </canvas> <script> var c = document.getElementById ("myCanvas").getContext ("2d"); var boxSize = 25; var numBoxes = 1; var x = 1000; var dx = 1; var y = 100; var dy = 1; var a = 0.01; var da = 0.1; var size = 20; var w = c.canvas.width; var h = c.canvas.height;

JavaScript setInterval immediately run

£可爱£侵袭症+ 提交于 2019-12-02 06:39:40
I found a solution to run interval in javascript immidiately, not waiting for a first "timeout" setInterval(function hello() { console.log('world'); return hello; }(), 2500); But problem is this solution isn't working is construction like this (function () { window.Banner = { doMagic: function () { setInterval(function magic() { console.log('magic'); return magic; }, 2500); } } })(); Banner.doMagic(); I've tried to return Banner method, to name it and return and no success. Point is what in real construction is much more complex, so i can't just rewrite it to "return setTimeout" solution, as

Pure Javascript - setInterval (1s), setAttribute

▼魔方 西西 提交于 2019-12-02 06:38:26
I'd like to change the color of the sqaure ( #myID: width = height = 100px ) every second. (To check if that switch loop works, in every "case" I wrote console.log("smth happened"); .) But the color of this square does not change. "FIDDLE" Next thing, every second document.getElementById('myID') is written to a new formed variable thesquare . How to make the variable global, outside the function? Javascript: var i = 0; function changecolor() { var thesquare = document.getElementById('myID'); switch (i) { case 0 : thesquare.setAttribute("background-color","red"); ++i; break; case 1 : thesquare

setinterval says not defined function but it is

≡放荡痞女 提交于 2019-12-02 05:20:37
i have this function which i define inside HEAD: <script type="text/javascript" src="http://code.jquery.com/jquery-1.11.1.min.js"> function live() { $.get("http://mydomain.com/script.php", function(data){ var timer = data; var elm = document.getElementById("live"); if (timer == 1){ elm.style.display = 'block'; } else{ elm.style.display = 'none'; } }); } </script> and then i do a loop like this at the very end of my document: <script type="text/javascript"> setInterval(live,10000); </script> but i get an error saying live is not defined. Why is that? Could you please tell me what im doing wrong

javascript || Angular2/6: Calling setInterval multiple times but last timerId is not stopping even though clearInterval called

怎甘沉沦 提交于 2019-12-02 05:18:19
Requirement: User scans multiple job numbers, for each job number , I need to call one API and get the total job details and show it in a table below the scanned text box. User don't want to wait until API call finishes. He will scan continuously irrespective of details came or not. What I have done: I have taken one variable jobNumberList which stores all the job numbers the user scanned I am continuously calling the API, with those job numbers. When API, gives response , then I am adding to the table I created one method called m1() m1() => this method will compare the jobNumberList with the

前端之BOM和DOM

左心房为你撑大大i 提交于 2019-12-02 04:55:18
前端之BOM和DOM 1 | 0 前戏 到目前为止,我们已经学过了JavaScript的一些简单的语法。但是这些简单的语法,并没有和浏览器有任何交互。 也就是我们还不能制作一些我们经常看到的网页的一些交互,我们需要继续学习BOM和DOM相关知识。 JavaScript分为 ECMAScript,DOM,BOM。 BOM(Browser Object Model)是指浏览器对象模型,它使 JavaScript 有能力与浏览器进行“对话”。 DOM (Document Object Model)是指文档对象模型,通过它,可以访问HTML文档的所有元素。 Window对象是客户端JavaScript最高层对象之一,由于window对象是其它大部分对象的共同祖先,在调用window对象的方法和属性时,可以省略window对象的引用。例如:window.document.write()可以简写成:document.write()。 1 | 1 window对象 所有浏览器都支持 window 对象。它表示浏览器窗口。 **如果文档包含框架(frame 或 iframe 标签),浏览器会为 HTML 文档创建一个 window 对象,并为每个框架创建一个额外的 window 对象。* **没有应用于 window 对象的公开标准,不过所有浏览器都支持该对象。* 所有 JavaScript