Skip to content

Instantly share code, notes, and snippets.

@whatisjasongoldstein
Last active December 14, 2015 04:09
Show Gist options
  • Save whatisjasongoldstein/7b367c1de43b36b9b9a7 to your computer and use it in GitHub Desktop.
Save whatisjasongoldstein/7b367c1de43b36b9b9a7 to your computer and use it in GitHub Desktop.
var Awesome = function(){
function stripInlineStyle(element){
$(element).attr('style','');
}
$('.box').on({
'dropover' : function(ev, drop, drag) {
$(this).addClass('highlight');
},
'dropout' : function(ev, drop, drag) {
$(this).removeClass('highlight');
},
'dropon' : function(ev, drop, drag) {
alert('Hit!');
var counter = $(drop.element).find('b');
var num = drag.element.attr('data-id');
counter.html(num);
stripInlineStyle(drag.element);
$(this).removeClass('highlight');
},
'dropend': function(ev, drop, drag) {
alert('miss');
stripInlineStyle(drag.element);
console.log('Drag ended!');
$(this).removeClass('highlight');
}
});
return {};
}();
<html>
<head>
<title>Example</title>
<link rel="stylesheet/less" type="text/css" href="style.less">
</head>
<body>
<h1>Example</h1>
<ul class="items">
<li data-id="1">Foobar</li>
<li data-id="2">Lorem Ipsum</li>
<li data-id="3">Coffee hat</li>
</ul>
<div class="box">
<b>&nbsp;</b>
</div>
<script src="jquery-1.8.0.min.js"></script>
<script src="jquerypp.custom.js"></script>
<script src="awesome.js"></script>
<script src="less-1.3.3.min.js"></script>
</body>
</html>
body {font-family: helvetica; line-height: 1.66em;}
.box {background: #ccc; width: 10em; height: 6em; -webkit-transition: 0.25s linear background;
b {display: inline-block; padding: 0.25em 1em; background: red; border-radius: 2em; color:white;
text-align: center; margin:1em; }
&.highlight {background: yellow;}
}
.items {padding:0; margin:1em 0;
li {background:red; display: inline-block; padding: 0.5em; cursor: pointer;}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment