Pen Settings



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


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


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.


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.


                <div class="box" id="box">
  <div id="ccc" class="aaa"></div>


                .box {
  width: 60%;
  height: 60vh;
  margin: 200px auto;
  /*display: flex;*/
  /*justify-content: center;*/
  /*align-items: center;*/
  position: relative;
  border: 2px solid red;

.aaa {
  position: absolute;
  width: 50px;
  height: 50px;
  background-color: rgb(245, 230, 99);
  border: 10px solid rgba(136, 136, 136, 0.5);
  border-radius: 50%;

.aaa:hover {
  cursor: pointer;
  border-width: 20px;

.aaa:active {
  background-color: rgba(168, 218, 220, 1);



                /* mousedown 鼠标进入
 *  mousemove 鼠标移动
 *  mouseup 鼠标离开
 * */
let box = document.querySelector("#box");
let ccc = document.querySelector("#ccc");

ccc.onmousedown = function (event) {
  // 子盒子
  let w = ccc.getBoundingClientRect().width / 2;
  let h = ccc.getBoundingClientRect().height / 2;
  // 大盒子-小盒子
  let width = box.getBoundingClientRect().width - w;
  let height = box.getBoundingClientRect().height - h;
  // 按下的位置距离左侧的差值
  let x = event.clientX - this.offsetLeft;
  let y = event.clientY - this.offsetTop;
  // 移动
  document.onmousemove = function (e) {
    // 移动的坐标-左侧的坐标=子盒子的坐标
    let x1 = e.pageX - x;
    let y1 = e.pageY - y;
    if (-w < x1 && x1 < width) { = x1 + "px";
    if (-h < y1 && y1 < height) { = y1 + "px";
  // 抬起
  document.onmouseup = function () {
    document.onmousemove = null;
    document.onmouseup = null;