We Lab8
We Lab8
UI22EC85
Using jQuery operations, complete the following assignments.
1. Creating a contextual menu. Display a menu with a few menu items in it. When
any menu item is hovered over (mouse pointer is moved over it), display the
information related to it, and also, that menu item should be highlighted.
CODE:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Contextual Menu</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<style>
#contextMenu {
position: absolute;
display: none;
background: #fff;
padding: 10px;
width: 150px;
.menu-item {
padding: 5px;
cursor: pointer;
.menu-item:hover {
background-color: lightblue;
#info {
margin-top: 10px;
font-weight: bold;
color: #333;
</style>
</head>
<body>
<div id="contextMenu">
</div>
<p id="info"></p>
<script>
$(document).ready(function() {
$(document).on("contextmenu", function(e) {
return false;
});
$(document).click(function() {
$("#contextMenu").fadeOut();
});
$(".menu-item").hover(function() {
$("#info").text($(this).data("info"));
});
});
</script>
</body>
</html>
OUTPUT:
2. You have two buttons on the web page, with the text Bold and Italic on them,
respectively. Create a word-balloon effect when either of the buttons is clicked.
CODE:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<style>
button {
margin: 10px;
font-size: 16px;
cursor: pointer;
.balloon {
position: absolute;
display: none;
background: yellow;
padding: 10px;
border-radius: 10px;
font-size: 14px;
font-weight: bold;
</style>
</head>
<body>
<button id="boldBtn">Bold</button>
<button id="italicBtn">Italic</button>
<script>
$(document).ready(function() {
$("button").click(function(e) {
balloon.css({
left: e.pageX + 20
}).fadeIn().delay(1000).fadeOut(500, function() {
$(this).remove();
});
});
});
</script>
</body>
</html>
OUTPUT:
3. Create a Horizontal Image Slider. You have to make an image gallery
(consisting of five or more images) in which initially three or a few images will be
displayed. By using the horizontal scroll bar, you can scroll, and the rest of the
images will be displayed.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script src="jquery-3.7.1.min.js"></script>
<style>
.slider-container {
white-space: nowrap;
.slider img {
</style>
</head>
<body>
<div class="slider-container">
<div class="slider">
</div>
</div>
<script>
$(document).ready(function() {
$(".slider-container").on("wheel", function(e) {
e.preventDefault();
this.scrollLeft += e.originalEvent.deltaY;
});
});
</script></bodY>
</html>
OUTPUT:
Conclusion: