小编Gag*_*ago的帖子

在javascript中保存拖放的位置

所以我有这个拖放脚本。我想做的是保存拖动项目的位置。所以如果有人刷新页面。拖动的图像应保留在同一位置。我只想在 javascript 中执行此操作

.fill {
      background-image: url('https://source.unsplash.com/random/150x150');
      height: 150px;
      width: 150px;
      cursor: pointer;
    }
    
    .hold {
      border: solid 5px #ccc;
    }
    
    .empty {
      height: 56rem;
        width: 36rem;
        margin: 10px;
        border: solid 3px salmon;
        background: white;
      }
    
    
    .hovered {
      background: #f4f4f4;
      border-style: dashed;
    }
Run Code Online (Sandbox Code Playgroud)
<!DOCTYPE html>
    <html lang="en" dir="ltr">
      <head>
      <link rel="stylesheet" href="style.css" />
      <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
        <meta charset="utf-8">
        <title></title>
      </head>
      <body>
    
        <div class="container">
          <div class="row">
            <div class="col-md-6">
              <div class="empty">
                <div class="fill" draggable="true"> </div>
              </div>
            </div>
            <div class="col-md-6">
              <div …
Run Code Online (Sandbox Code Playgroud)

html javascript css

5
推荐指数
1
解决办法
5438
查看次数

Javascript(本地存储)仅存储一个值。我如何存储一切?

我从开放的API获取用户数据,将其存储在本地存储中,可以显示所有数据,但是只有第一个值被保存在本地存储中。如何存储所有数据?

我的代码:

String.prototype.capitalize = function() {
  return this.charAt(0).toUpperCase() + this.slice(1);
}

function createNode(element) {
  return document.createElement(element);
}

function append(parent, element ) {
  return parent.appendChild(element);
}

const ul = document.getElementById('authors');
const url = 'https://randomuser.me/api/?results=10';

fetch(url)
  .then((resp) => resp.json())
  .then(function(data) {

    let authors = data.results;

    return authors.map(function(author) {

      const myObj = {
        name: `${author.name.first}`,
        lastname : `${author.name.last}`,
        email : `${author.email}`,
        location : `${author.location.city}, ${author.location.street}`,
        phone : `${author.phone}`
      }

      let li = createNode('li'),
          img = createNode('img'),
          span = createNode('span');

      let myObj_serialized = JSON.stringify(myObj); …
Run Code Online (Sandbox Code Playgroud)

javascript local-storage

2
推荐指数
1
解决办法
230
查看次数

标签 统计

javascript ×2

css ×1

html ×1

local-storage ×1