'Div does not follow the mouse

In the following code, I hope my div will follow my mouse in red background but it does not, what's the reason for that?

CSS

.dropdown1 {
  position: absolute;
  left: 150px;
  top: 10px;
  background: #2b4557;
  padding: 4px 8px;
  font-size: 12px;
  line-height: 18px;
  color: #fff;
}

JSX

import "./styles.css";
import { useRef } from "react";

export default function App() {
  const descBox = useRef(null);
  const handleMove = (e) => {
    console.log(e.clientX, e.clientY);
    descBox.current.style.left = e.clientX;
    descBox.current.style.top = e.clientY;
  };
  return (
    <div
      onMouseMove={handleMove}
      style={{ height: "300px", width: "100%", backgroundColor: "red" }}
    >
      <div className="dropdown1" ref={descBox}>
        123asdfsfdafffasdfasfdsajkj
      </div>
    </div>
  );
}

Please run the code in Codesandbox

And here's a screenshot: enter image description here



Solution 1:[1]

In the doGet() context, you cannot find if some user somewhere in the world has the spreadsheet open, nor which sheet and cell they currently happen to have active.

One way to make the active sheet and cell available would be to recast your web app as a container-bound script project or an add-on. Bound scripts and add-ons have the spreadsheet and user context, while web apps only have the user context (or the developer user context).

Bound scripts and add-ons are essentially the same implementation-wise, but a bound script is much easier to deploy. The drawbacks of a bound script are that the every user will have to go through the script authorization flow the first time they start the script, and users also get edit access to the source code. Add-ons also require authorization, but the source code is not revealed.

The user interface would have to be shown in a sidebar or a dialog box. The UI code would probably not need too many changes, but client-server communication would have to be done with google.script.run instead of doPost().

If you cannot implement your code as an add-on, you can append the URL to the first blank row of the first sheet, like this:

function record_data(e, fileUrl) {
  const sheet = SpreadsheetApp.getActive().getSheets()[0];
  sheet.appendRow([fileUrl]);
}

Use Spreadsheet.getSheetByName() to use another sheet instead of the first sheet.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1