In: Computer Science
Use HTML, CSS, jQuery and Bootstrap to do the following:
1. Add four buttons "Start", "Stop", "Back", "Reset". <button type="button">
2. Add "glyphicon-shopping-cart" to <div id="sc"
style="font-size: 100px; color: blue; ">.
Use CSS in embeded style to set
<style type="text/css">
#sc{
border-style: dotted; /* Required to animate border width */
border-color: red;
border-width: 0;
}
</style>
3. <script>
- "Start", call "animate()" function to move it to right by
300px for
each click, speed is 2000. left: "+=300px". Hint: chaining
call animate({borderBottomWidth: "0px"},500)
in css, border-bottom-with:
- "Stop", call "stop()" function stop movement, show bottom
border color
in red. Hint: use "Chaining" to call stop() and
animate({borderBottomWidth: "10px"},500)
- "Back", call "animate()" function to move it to left by 300px
for
each click, speed is 2000.
- "Reset", call "animate()" function to the begining positon.
left: "0".
"Chaining" call.
Working code implemented in HTML, CSS, jQuery & Bootstrap and appropriate comments provided for better understanding.
Source Code:
<!doctype html>
<html lang-"en">
<head>
<meta charset-"utf-8"/>
<title>Assignment</title>
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
integrity="sha384-
BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
crossorigin="anonymous">
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstraptheme.
min.css" integrity="sha384-
rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp"
crossorigin="anonymous">
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script
src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"
integrity="sha384-
Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa"
crossorigin="anonymous"></script>
<script>
$(document).ready(function() {
$("#start").click(function() {
$("#sc").animate({borderBottomWidth:
"0"},500).animate({
marginLeft: "+=300px",
}, 2000);
});
$("#stop").click(function() {
$("#sc").stop().animate({borderBottomWidth:
"10px"},500).css("borderBottomWidth", "10px");
});
$("#back").click(function() {
$("#sc").animate({borderBottomWidth:
"0"},500).animate({
marginLeft: "-=300px",
}, 2000);
});
$("#reset").click(function()
{
$("#sc").animate({borderBottomWidth: "0"},500).animate({
marginLeft: "0px",
}, 500);
});
});
</script>
<style media="screen">
.button-container {
padding: 10px
0px 50px 10px; /*T10-R0-B50-L10*/
}
#sc {
display:
inline-block; /*only take up space needed*/
border-style:
dotted;
border-color:
red;
border-width:
0;
font-size:
100px;
color:
blue;
}
</style>
</head>
<body>
<div
class="button-container">
<button
id="start" type="button"
name="button">Start</button>
<button
id="stop" type="button" name="button">Stop</button>
<button
id="back" type="button" name="button">Back</button>
<button
id="reset" type="button"
name="button">Reset</button>
</div>
<!--START animate({borderBottomWidth: "0px"},500)
-->
<!--STOP stop().animate({borderBottomWidth: "10px"},500)
-->
<!--BACK animate() -->
<!--RESET animate() -->
<div id="sc">
<span
class="glyphicon glyphicon-shopping-cart"></span>
</div>
</body>
</html>
Sample Output Screenshots: