in Education by
How can I apply my div position x value to a variable? And how to iterate it in a for loop?
#object{ position:absolute; width:10px; height:10px; background:#ff8800; } function play(){ // here how to Add my div position to a variable And Applaying of Iteration In Forloop // how to change position Of Its in For loop for(){ } // I am Strucked At Here } JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Try This With Logic Of Play And Stop With Some UI Elements . var speed = 5; function play(){ if($("#object").data("play")) { setTimeout(function(){ var count = $("#object").position().left; count += speed; $("#object").css("left",count); requestAnimationFrame(play); },500); } } $("#play").click(function(){ $("#object").data("play",true); $('#object').css('background','green'); play(); $('#stop').css('display','block'); }); $("#stop").click(function(){ $("#object").data("play",false); $('#object').css('background','#ff8800'); $('#stop').css('display','none'); }); input { position:absolute; width:50px; height:25px; top:100px; } #play { background:green; border:none; color:#fff; border-radius:15px; left:35px; } #stop { background:#ff8800; border:none; border-radius:15px; color:#fff; left:35px; display:none; } #object{ position:absolute; width:10px; height:10px; background:#ff8800; }
Run code snippetExpand snippet

Related questions

0 votes
    [reposting deleted question with more detail] I've searched for an answer to this but not found a reference ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 19, 2022 in Education by JackTerrance
0 votes
    [reposting deleted question with more detail] I've searched for an answer to this but not found a reference ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 11, 2022 in Education by JackTerrance
0 votes
    [reposting deleted question with more detail] I've searched for an answer to this but not found a reference ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 10, 2022 in Education by JackTerrance
0 votes
    I Know I can do this with static HTML, but I want to create dynamically, and I am struggling a ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 12, 2022 in Education by JackTerrance
0 votes
    I Know I can do this with static HTML, but I want to create dynamically, and I am struggling a ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 8, 2022 in Education by JackTerrance
0 votes
    Here is my JSFiddle Preview is shown in div box. I want to add close option on right top. How ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 10, 2022 in Education by JackTerrance
0 votes
    I have a landing page with sticky header. When user start scroll and the page displays .second-section . ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 26, 2022 in Education by JackTerrance
0 votes
    I have a landing page with sticky header. When user start scroll and the page displays .second-section . ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 14, 2022 in Education by JackTerrance
0 votes
    I have a landing page with sticky header. When user start scroll and the page displays .second-section . ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    In my web application, I have tabs and if any of the tab is clicked, the corresponding page will ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 18, 2022 in Education by JackTerrance
0 votes
    In my web application, I have tabs and if any of the tab is clicked, the corresponding page will ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 18, 2022 in Education by JackTerrance
0 votes
    In my web application, I have tabs and if any of the tab is clicked, the corresponding page will ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 18, 2022 in Education by JackTerrance
0 votes
    I have the access to this DOM node in temp1.$el. And here is the content which the above variable ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 26, 2022 in Education by JackTerrance
0 votes
    I have the access to this DOM node in temp1.$el. And here is the content which the above variable ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 14, 2022 in Education by JackTerrance
0 votes
    I have the access to this DOM node in temp1.$el. And here is the content which the above variable ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 13, 2022 in Education by JackTerrance
...