javascript - Transfering Variable Values Between Scopes -


i'm sick , tired of thinking it. okay there draggable blue box,; if touches red box, redbox changes position randomly. mixed whole codes, know; i'm dumb @ coding part. couldn't figure mistakes. need knowledge me situation.

the jquery part.

$(document).ready(function() { var kol = 253; var score = 0; var redboxwidth = $('#redbox').width(); var redboxheight = $('#redbox').height(); var redt = $('#redbox').position().top; var redl = $('#redbox').position().left; var redbox = $(".redbox");  var bluecoordinates = function(element1) {     var top;     var left;     var blueboxwidth = $('#bluebox').width();     var blueboxheight = $('#bluebox').height();     element1 = $(element1);     top = element1.position().top;     left = element1.position().left;      $('#results').text('x: ' + left + ' ' + 'y: ' + top);     $('#results3').text('redl: ' + redl + 'redx: ' + redt);     settimeout(function() {         if ((top > (redx) && left > (redy))) {             settimeout(function() {                 $('#results2').text(top + "  " + redx + "  " + redy + "  " + redboxheight + "   " + redboxwidth);             });             redx = (math.random() * ($('#canvas').width() - redboxwidth)).tofixed();             redy = (math.random() * ($('#canvas').height() - redboxheight)).tofixed();             redbox.css({                 'position': 'absolute',                 'left': redx + 'px',                 'top': redy + 'px'              });           }         bluecoordinates();     }); }  $('#bluebox').draggable({     drag: function() {         bluecoordinates('#bluebox');     } }); 

});

the html part

<div id="canvas"> <div id="bluebox"></div> <div id="redbox" class="redbox"></div> </div> <div id="results" class="results"></div> <div id="results1" class="results"></div> <div id="results2" class="results"></div> <div id="results3" class="results"></div> 

css part

# canvas { width: 500px; height: 400px; background: #ccc; position: absolute; top: 0px; left: 0px; }# bluebox { position: absolute; top: 0; left: 0; width: 100px; height: 100px; background: blue; cursor: move; } .redbox { position: absolute; top: 250px; left: 350px; width: 100px; height: 100px; background: red; cursor: move; } .results {  text - align: center; position: relative; top: 400px; left: 25px; } 

only thing needed transferring values of redx , redy redt , redl...

 if ((top > (redx) && left > (redy))) {         settimeout(function() {             $('#results2').text(top + "  " + redx + "  " + redy + "  " + redboxheight + "   " + redboxwidth);         });         redx = (math.random() * ($('#canvas').width() - redboxwidth)).tofixed();         redy = (math.random() * ($('#canvas').height() - redboxheight)).tofixed();       redt=redy;       redl=redx;         redbox.css({             'position': 'absolute',             'left': redx + 'px',             'top': redy + 'px'          }); 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -