Users have been granted the ability to input their characters onto the screen and manipulate each character's position.
However, I only want users to move these characters within a specific square or rectangle area, limiting their placement options.
HTML
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js">
</script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.min.js"></script>
<div id="word-container">
<div class="character">P</div>
<div class="character">l</div>
<div class="character">a</div>
<div class="character">c</div>
<div class="character">e</div>
<div class="character">m</div>
<div class="character">a</div>
<div class="character">r</div>
<div class="character">k</div>
</div>
<br>
<br>
<form action="demo_form">
Word:
<input type="text" id="my-word" name="fname">
<br>
<button type="button" id="make-word">Make word</button>
</form>
CSS
.character {
width: 10px;
height: 15px;
font-size: 50px;
display: inline;
cursor: drag;
}
JQuery
function initDragable($elements) {
$elements.draggable();
}
initDragable($('.character'));
$(function(){
$('#make-word').click(function() {
var $this = $(this);
var letters = $('#my-word').val().split('');
letters = '<div class="character">'+letters.join('</div><div class="character">')+'</div>';
initDragable($('#word-container').html(letters).find('.character'));
});
});