Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="dm">
  <div class="dm_screen">
    <div class="dm_mask"></div>
    <div class="dm_show">
      <!-- <div>text message</div>  -->
    </div>
  </div>
  <div class="send">
    <div class="s_fiter">
      <div class="s_con">
        <p>
          <input placeholder="说点什么?" class="s_txt" type="text" />
        </p>
        <p>
          <input type="button" value="发 射" class="s_sub" />
          <input type="button" value="清 屏" class="s_del" />
        </p>
      </div>
    </div>
  </div>
</div>
              
            
!

CSS

              
                	.s_txt {
	  width: 388px;
	  height: 34px;
	  border-radius: 3px;
	  border: 1px solid rgb(204, 204, 204);
	  padding-left: 10px;
	}
	
	.s_sub {
	  border: 1px solid rgb(230, 80, 30);
	  color: rgb(230, 80, 0);
	  border-radius: 3px;
	  text-align: center;
	  padding: 0;
	  height: 35px;
	  line-height: 35px;
	  font-size: 14px;
	  width: 159px;
	  background-color: white;
	}
	
	.s_del {
	  border: 1px solid rgb(176, 168, 165);
	  color: rgb(176, 168, 165);
	  border-radius: 3px;
	  text-align: center;
	  padding: 0;
	  height: 35px;
	  line-height: 35px;
	  font-size: 14px;
	  width: 159px;
	  background-color: white;
	}
	
	.dm {
	  margin: 20px;
	  text-align: center;
	}
	
	.dm_screen {
	  border: 1px solid rgb(229, 229, 229);
	}
	
	.dm .dm_screen .dm_mask {
	  width: 100%;
	  height: 380px;
	}
	
	.dm .dm_screen .dm_show div {
	  font-size: 22px;
	  line-height: 36px;
	  font-weight: 500;
	  color: #fff;
	  position: absolute;
	  left: 0;
	  top: 0;
	}
              
            
!

JS

              
                	$(document).ready(function() {
    //提示:已经在页面导航部分的Settings中的JavaScript部分引入了wildog.js和jquery.js
	  //在www.wildog.com 注册一个账号,创建一个应用,自动生成一个url,替换下边url即可
	  var ref = new Wilddog("https://danwu.wilddogio.com/messages");
	  var arr = [];
	  //把数据提交到野狗云
	  $(".s_sub").click(function() {
	    var text = $(".s_txt").val();
	    ref.child('message').push(text);
	    $(".s_txt").val('');
	  });
	  //响应按键点击事件
	  $(".s_txt").keypress(function(event) {
	    if (event.keyCode == "13") {
	      $(".s_sub").trigger('click');
	    }
	  });
	  //响应按键清除事件
	  $(".s_del").click(function() {
	    ref.remove();
	    arr = [];
	    $('.dm_show').empty();
	  });
	  //监听云端数据变更,云端数据变化,弹幕框里数据也跟着变化。
	  ref.child('message').on('child_added', function(snapshot) {
	    var text = snapshot.val();
	    arr.push(text);
	    var textObj = $("<div class=\"dm_message\"></div>");
	    textObj.text(text);
	    $(".dm_show").append(textObj);
	    moveObj(textObj);
	  });

	  ref.on('child_removed', function() {
	    arr = [];
	    $('.dm_show').empty();
	  });
	  //按照时间规则显示弹幕内容。	
	  var topMin = $('.dm_mask').offset().top;
	  var topMax = topMin + $('.dm_mask').height();
	  var _top = topMin;

	  var moveObj = function(obj) {
	    var _left = $('.dm_mask').width() - obj.width();
	    _top = _top + 50;
	    if (_top > (topMax - 50)) {
	      _top = topMin;
	    }
	    obj.css({
	      left: _left,
	      top: _top,
	      color: getRandomColor()
	    });
	    var time = 20000 + 10000 * Math.random();
	    obj.animate({
	      left: "-" + _left + "px"
	    }, time, function() {
	      obj.remove();
	    });
	  }

	  var getRandomColor = function() {
	    return '#' + (function(h) {
	      return new Array(7 - h.length).join("0") + h
	    })((Math.random() * 0x1000000 << 0).toString(16))
	  }

	  var getAndRun = function() {
	    if (arr.length > 0) {
	      var n = Math.floor(Math.random() * arr.length + 1) - 1;
	      var textObj = $("<div>" + arr[n] + "</div>");
	      $(".dm_show").append(textObj);
	      moveObj(textObj);
	    }

	    setTimeout(getAndRun, 3000);
	  }

	  jQuery.fx.interval = 50;
	  getAndRun();
	});
              
            
!
999px

Console