javascript used in webpage
javascript used in webpage
[ this funtion is visible in all the pages except for, { how to get to lallo, lallo attractions, lallo
accomodations, and cabibi pages} ]
Function updateDateTime()
This function updates the date and time displayed on the page.
1. const now = new Date();: Creates a new Date object, which represents the current date and time.
2. const options = { ... };: Defines an object options that specifies the format of the date and time string. The
properties of the object are:
weekday: specifies the weekday (e.g., "Monday", "Tuesday", etc.)
year: specifies the year (e.g., "2023")
month: specifies the month (e.g., "January", "February", etc.)
day: specifies the day of the month (e.g., "1", "2", etc.)
hour: specifies the hour in 24-hour format (e.g., "14", "15", etc.)
minute: specifies the minute (e.g., "30", "45", etc.)
second: specifies the second (e.g., "00", "15", etc.)
3. const dateTimeString = now.toLocaleString('en-US', options);: Uses the toLocaleString() method to
format the now date object according to the options object. The en-US parameter specifies the locale to use for formatting
(in this case, English, United States).
4. document.getElementById('date-time').innerText = dateTimeString;: Sets the inner text of an HTML element
with the ID date-time to the formatted date and time string dateTimeString.
The script calls the updateDateTime() function once, which updates the date and time displayed on the
page.
In summary, this script updates the date and time displayed on the page by formatting the current date
and time using the toLocaleString() method and setting the inner text of an HTML element with the
ID date-time to the formatted string.
The first part of the script adds an event listener to the submit event of the first form element on the page.
The second part of the script adds an event listener to the scroll event of the window object.
7. else {...}: If the user has not scrolled far enough down the page:
tableContainer.classList.remove('scrolled');: Removes the class scrolled from
the tableContainer element.
JAvascript [transparency, about lallo, and servces page] [ajay buttons ti adda java na]
This script is used to create a simple tabbed interface, where clicking on a button reveals a corresponding
section of content. Here's a breakdown of how it works:
Selecting elements
1. buttons.forEach((button, index) => {...});: Loops through each button and adds an event listener to
its click event. The index variable keeps track of the current button's index in the array.
2. button.addEventListener('click', () => {...});: Adds an event listener to the button's click event.
How it works
isInViewport function
This function checks if an element is within the viewport (i.e., visible on the screen). It takes an element as
an argument and returns a boolean value indicating whether the element is in the viewport.
1. const rect = element.getBoundingClientRect();: Gets the bounding rectangle of the element, which
contains information about the element's position and size.
2. The function then checks four conditions to determine if the element is in the viewport:
rect.top >= 0: The top edge of the element is above the top edge of the viewport.
rect.left >= 0: The left edge of the element is to the right of the left edge of the viewport.
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight): The bottom edge of
the element is below the bottom edge of the viewport.
rect.right <= (window.innerWidth || document.documentElement.clientWidth): The right edge of the
element is to the left of the right edge of the viewport.
3. If all conditions are true, the function returns true, indicating that the element is in the viewport.
handleIntersection function
This function is a callback that will be called whenever an observed element intersects with the viewport. It
takes two arguments: entries and observer.
1. entries.forEach(entry => {...});: Loops through each entry in the entries array.
2. For each entry, it checks if the element is intersecting with the viewport ( entry.isIntersecting).
If it is, it sets the element's visibility style to visible.
If not, it sets the element's visibility style to hidden.
3. It also sets an animation style on the element using entry.target.style.animation = "slow 1.5s ease-in-
out";.
IntersectionObserver options
1. root: null: The root element for the observer. In this case, it's set to null, which means the observer will
use the viewport as the root.
2. rootMargin: '0px': The margin around the root element. In this case, it's set to 0px, which means there's no
margin.
3. threshold: 0.3: The threshold value determines when the observer should trigger the callback. In this case,
it's set to 0.3, which means the callback will be triggered when the element is at least 30% visible in the
viewport.
SCRIPT IN WEBPAGE
Creating the IntersectionObserver
The script creates a new IntersectionObserver instance, passing the handleIntersection function and
the options object as arguments.
Observing elements
The script selects all elements with the class card using document.querySelectorAll('.card'). It then loops
through each card element and adds it to the observer using observer.observe(card).
In summary, this script uses the IntersectionObserver API to observe a set of elements (cards) and trigger a
callback function when they intersect with the viewport. The callback function sets the element's visibility
and animation styles based on whether it's intersecting with the viewport.