JavaScript Change element class while dragging change element class javascript,change element class jquery,change element

I am trying to change element class or any css property while dragging and it depends on elements position. So this is what i got so far:

https://jsfiddle.net/twfegqgc/

So it changes when element passes half of window but when it comes to end of window width it doesn't change and it should. So that is my problem.

HTML

<div id="sun" class="yellow"></div>
<div class="position"></div>
<div class="window"></div>

JS

var sun = $("#sun");

sun.draggable();

$("#sun").bind("drag", function(event, ui) {
    var halfWidth = $(window).width() / 2;
    var left = $(this).offset().left + 100;
    var windowWIdth = $(window).width() - 200;

    $('.position').html(left);
    $('.window').html(windowWIdth);

    if(left > halfWidth) {
        sun.removeClass('yellow');
        sun.addClass('red')
    } else if (left == windowWIdth) {
        sun.removeClass('red');
        sun.addClass('black')
    }

});

I am actually trying to create answer to some other question here.

Answer:1

In my app.js file I have I am exporting an object with properties and values. On the route, I am including the file but I am getting the value as undefined. If I don't pass in the argument "users" in ...

In my app.js file I have I am exporting an object with properties and values. On the route, I am including the file but I am getting the value as undefined. If I don't pass in the argument "users" in ...

  1. undefined value from json
  2. value undefined in javascript
  3. value undefined in jquery
  4. value undefined in angular
  5. value undefined in php
  6. undefined value in math
  7. value of undefined
  8. undefined value in javascript object
  9. undefined value in python
  10. undefined value in array javascript
  11. undefined value in java
  12. undefined value in js
  13. undefined value in mongodb
  14. undefined value in excel
  15. undefined value in ajax
  16. undefined value in c#
  17. undefined value in perl
  18. undefined value in typescript
  19. undefined value in html
  20. ng model value undefined

I have an array that I want to transform into an object. For example: const arr = [{id: 1, key: ''}, {id: 2, key: ''}]; I want the result to be: const object = { 1: {id: 1, key: ''}, 2: { id: 2, ...

I have an array that I want to transform into an object. For example: const arr = [{id: 1, key: ''}, {id: 2, key: ''}]; I want the result to be: const object = { 1: {id: 1, key: ''}, 2: { id: 2, ...

I tried creating mixing in a getter into a JS object via the spread operator syntax, however it always seems to return null. HTML: <body> <div id="wrapperA"></div> <div id="...

I tried creating mixing in a getter into a JS object via the spread operator syntax, however it always seems to return null. HTML: <body> <div id="wrapperA"></div> <div id="...

I have an two elements fruits and crates fruits is an array containing a list of different fruits like: ["apple","orange","mango","pear"] crates is an array of objects which contains fruits in it ...

I have an two elements fruits and crates fruits is an array containing a list of different fruits like: ["apple","orange","mango","pear"] crates is an array of objects which contains fruits in it ...