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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              
	<main class="main">
		<div class="left" id="left">
			<div class="txt-show">左边区域</div>
			<div id='txt1' draggable="true" class="dragable txt txt1">可移动的文字一</div>
			<div id='txt2' draggable="true" class="dragable txt txt2">可移动的文字二</div>
			<div id='txt3' draggable="true" class="dragable txt txt3">可移动的文字三</div>
			<div id='txt4' draggable="true" class="dragable txt txt4">可移动的文字四</div>
			<div id='txt5' draggable="true" class="dragable txt txt5">可移动的文字五</div>
		</div>
		<div class="right" id='right'>
			<div class="txt-show">右边区域</div>
		</div>
	</main>
            
          
!
            
              .main {
			display: flex;
			justify-content: space-around;
		}
		.left {
			width: 300px;
			height: 500px;
			margin-right: 10px;
			border: 1px solid red;
			text-align: center;
			box-sizing: border-box;
			padding: 1px;
		}
		.right {
			width: 300px;
			height: 500px;
			border: 1px solid lightseagreen;
			text-align: center;
			box-sizing: border-box;
			padding: 1px;
		}
		.txt {
			border: 1px solid gray;
			margin: 1px;
      padding: 5px;
			cursor: move;
		}
            
          
!
            
              
		let txtObj = document.getElementsByClassName('txt')
		for ( let i = 0; i < txtObj.length; i++) {
			txtObj[i].ondragstart = handle_start
			txtObj[i].ondrag = handle_drag
			txtObj[i].ondragend = handle_end
		}
		function handle_start(e) {
			e.dataTransfer.setData('Text', e.target.id)
			console.log('handle_start-拖动开始')
		}
		function handle_drag(e) {
			console.log('handle_drag-拖动中')
		}
		function handle_end(e) {
			console.log('handle_end-拖动结束')
		}

		let target = document.getElementById('right')
		target.ondragenter = handle_enter
		target.ondragover = handle_over
		target.ondragleave = handle_leave
		target.ondrop = handle_drop
		let leftTarget = document.getElementById('left')
		leftTarget.ondragenter = handle_enter
		leftTarget.ondragover = handle_over
		leftTarget.ondragleave = handle_leave
		leftTarget.ondrop = handle_drop

		function handle_enter(e) {
			e.preventDefault()
			console.log('handle_enter-进入目的地')
		}
		function handle_over(e) {
			e.preventDefault()
			let returnObj = e.dataTransfer.getData('Text')
			console.log(returnObj +'-handle_over-在目的地范围内')
		}
		function handle_leave(e) {
			e.preventDefault()
			let returnObj = e.dataTransfer.getData('Text')
			console.log(returnObj)
			console.log('handle_leave-没有放下就离开目的地')
		}
		function handle_drop(e) {
      e.stopPropagation();// 不再派发事件。解决Firefox浏览器,打开新窗口的问题。
			e.preventDefault()
			let returnObj = e.dataTransfer.getData('Text')
			if (returnObj) {
				e.target.appendChild(document.getElementById(returnObj))
			}
			console.log(returnObj + '-handle_drop-在目的地区释放')
		}
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console