Calculator Tools Calculator Tools
Create

Car Parts Fitting Game

Sep 22, 2023

About this app

A fun, interactive game that lets you fit car parts on a car image.

Car Parts Fitting Game

Related apps

Put this on your site

Source

                    <html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1">

<title>Car Parts Fitting Game</title>
<meta name="description" content="A fun, interactive game that lets you fit car parts on a car image.">
<meta name="keywords" content="car parts, game, interactive, fit parts">

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">

<script type="text/javascript">
try {
let carParts = {
'wheel': { 'top': '100px', 'left': '50px' },
'headlight': { 'top': '20px', 'left': '100px' },
// add more car parts here
};

function makeDraggable() {
$('.draggable').draggable({
revert: 'invalid',
start: function () {
$(this).addClass('dragging');
},
stop: function () {
$(this).removeClass('dragging');
}
});
}

function makeDroppable() {
$('.droppable').droppable({
accept: '.draggable',
drop: function (event, ui) {
let partId = ui.draggable.attr('id');
ui.draggable.position({
of: $(this),
my: 'center',
at: 'center'
});
ui.draggable.draggable('option', 'revert', false);
}
});
}

$(function() {
makeDraggable();
makeDroppable();
});
} catch (error) {
throw error;
}
</script>

<style>
/* App CSS Goes Here */
.draggable {
width: 50px;
height: 50px;
}
.dragging {
opacity: 0.5;
}
.droppable {
width: 200px;
height: 200px;
position: relative;
}
</style>
</head>
<body>
<div id="main-container" class="container">
<!-- App HTML Goes Here -->
<div id="car-image" class="droppable">
<!-- Car Image Goes Here -->
</div>
<div id="parts-container">
<img id="wheel" class="draggable" src="//path-to-your-wheel-image" />
<img id="headlight" class="draggable" src="//path-to-your-headlight-image" />
<!-- Add More Parts Here -->
</div>
</div>
</body>
</html>