dpjo15650 2019-05-04 11:38
浏览 58

如何让用户更改div的背景图像并保存给所有观众?

I have created a page where the user can place icons (change background) of the cells in the tables. I would like this to be a collaborative thing, so that the changes are saved to a server so that another user that will enter the website, or is already on the website will see the changes.

Conceptually I think I've got it down: I would need to store the changes in background(s) somewhere (a server) where when the page loads you can ask for the current state of the changes then every time someone draws something (js click) I need to update the state of the webpage (on the server).

I have searched for firebase or Myjson. However even after starting my search I have no clue where to start. I would be forever grateful if someone could give me a little push.

Right now the website works as follows:


<div class="toolbar">
    <div class="toolcontainer">
    <div id="i1"></div>
</div>
</div>

<div id="drawing">
    <div class="row">
      <div class="pixel"></div>
      <div class="pixel"></div>
      <div class="pixel"></div>
      <div class="pixel"></div>
      <div class="pixel"></div>
      <div class="pixel"></div>
      <div class="pixel"></div>
      <div class="pixel"></div>
      <div class="pixel"></div>
      <div class="pixel"></div> 
</div>
</div>
//variable with url stored inside
icon = '(icon.png)'


// onclick function classes 
$(".pixel").click(function() {
    //function that changes background to url
    $(this).css("background-image", "url(" + icon +")");
});


//id i1 till 23 + change var on click 
$('#i1').click(function (){
    icon = "icon1.png";
});

$('#i2').click(function (){
    icon = "icon2.png";
});


.toolbar{
    position: fixed;
    width: 100%;

    background-color: grey;
    border: black 1px solid;
}


.toolcontainer{
    width: 100%;
    height: 100%;
     display:flex;
}

#drawing{
    height: 14040px;
    width: 9933px;
    background-color: black;
    border-spacing: 1px;
    border: 1px solid black;
}

  .row {
      display: table-row;
    }

  .pixel {
    display: table-cell;
    background-color: white;
    width: 30px;
    height: 30px;
    }



#i1{
    position: relative;
    width: 3vw;
    height: 3vw;
    border: black 1px solid;
    display: inline-block;
    margin:0.7%;
    background-color: white;
    background-image: url("icon1.png");
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥50 切换TabTip键盘的输入法
    • ¥15 关于#网络安全#的问题:求ensp的网络安全,不要步骤要完成版文件
    • ¥15 可否在不同线程中调用封装数据库操作的类
    • ¥20 使用Photon PUN2解决游戏得分同步的问题
    • ¥15 微带串馈天线阵列每个阵元宽度计算
    • ¥15 keil的map文件中Image component sizes各项意思
    • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
    • ¥15 划分vlan后,链路不通了?
    • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
    • ¥15 Vue3 大型图片数据拖动排序