有没有一种方法可以将聊天记录中的<div>位置随机化?

问题描述

im试图编写一个代码,使来自Twitch聊天记录的消息在单独的屏幕上随机出现。就像每个新消息都出现在屏幕上的新位置一样。像这样:

(function makeDiv(){
var divsize = ((Math.random()*100) + 50).toFixed();
var color = '#'+ Math.round(0xffffff * Math.random()).toString(16);
$newdiv = $('<div/>').css({
    'width':divsize+'px','height':divsize+'px','background-color': color
});

var posx = (Math.random() * ($(document).width() - divsize)).toFixed();
var posy = (Math.random() * ($(document).height() - divsize)).toFixed();

$newdiv.css({
    'position':'absolute','left':posx+'px','top':posy+'px','display':'none'
}).appendTo( 'body' ).fadeIn(100).delay(300).fadeOut(200,function(){
   $(this).remove();
   makeDiv(); 
}); 

})();

这是聊天代码,即HTML:

<div id="log" class="sl__chat__layout">
</div>

<!-- chat item -->
<script type="text/template" id="chatlist_item">
  <div data-from="{from}" data-id="{messageId}">
    <span class="meta" style="color: {color}">
      <span class="badges">
      </span>
      <span class="name">{from}</span>
    </span>

    <span class="message">
      {message}
    </span>
  </div>
</script>

CSS

@import url(https://fonts.googleapis.com/css?family=Roboto:700);

* {
    box-sizing: border-box;
}

html,body {
    height: 100%;
    overflow: hidden;
}

body {
    text-shadow: 0 0 1px #000,0 0 2px #000;
    background: {background_color};
    font-family: 'Roboto';
    font-weight: 700;
    font-size: {font_size};
    line-height: 1.5em;
    color: {text_color};
}

#log>div {
    animation: fadeInRight .3s ease forwards,fadeOut 0.5s ease {message_hide_delay} forwards;
   -webkit-animation: fadeInRight .3s ease forwards,fadeOut 0.5s ease {message_hide_delay} forwards;
}

.colon {
    display: none;
}

#log {
    display: table;
    position: absolute;
    bottom: 0;
    left: 0;
    padding: 0 10px 10px;
    width: 100%;
    table-layout: fixed;
   }

#log>div {
    display: table-row;
}

#log>div.deleted {
    visibility: hidden;
}

#log .emote {
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;
    padding: 0.4em 0.2em;
    position: relative;
}

#log .emote img {
    display: inline-block;
    height: 1em;
    opacity: 0;
}

#log .message,#log .meta {
    vertical-align: top;
    display: table-row;
    padding-bottom: 0.1em;
     
}

#log .meta {
    width: 35%;
    text-align: left;
    padding-right: 0.5em;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;  
}

#log .message {
    word-wrap: break-word;
    width: 65%;
}

.badge {
     display: inline-block;
     margin-right: 0.2em;
     position: relative;
     height: 1em;
     vertical-align: middle;
    top: -0.1em;
}

.name {
    margin-left: 0.2em;
}

基本上它们都是结合在一起的。我认为我正在接近解决方案,我想我只需要设置消息的位置,以在每次出现新消息时更改位置。 JavaScript使我难以掌握,现在我完全迷路了,有人可以帮助我解决这个问题吗?预先感谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...