Is there a way to effortlessly bring life to a pre-designed image gallery through automation?

I created a responsive design using HTML5 and CSS3 based on a tutorial I watched on YouTube. However, the tutorial only covered the basics and I couldn't find any follow-up videos or references on the same topic. Despite searching through the channel's tutorials, I still haven't been able to find the missing information.

The code provided is fully adaptable for both mobile devices and computers.

To animate the gallery similar to the example shown in this image: , I am looking for a simple jQuery solution that can be applied to my existing structure. Can someone guide me on how to achieve this animation effect?

Answer №1

There are numerous techniques available to achieve the desired outcome using either pure JavaScript or jQuery.

After analyzing the HTML structure, it is evident that the data-key attribute plays a crucial role in determining the current image to be displayed within the gallery. This attribute establishes the connection between elements with classes ui-big-image, ui-thumbnail, and ui-article.

For elements with the class ui-big-image, they are initially hidden using the following CSS rule:

.ui-big-image {
  opacity: 0;
  -webkit-transform: translateX(-100%);
  transform: translateX(-100%);
}

The visibility of these elements is controlled by the CSS statement below:

.ui-big-image[data-active] {
  opacity: 1;
  -webkit-transform: translateX(0%);
  transform: translateX(0%);
}

Similarly, elements with the class ui-article are first hidden with this CSS declaration:

.ui-article {
  -webkit-transform: translateX(-100%);
  transform: translateX(-100%);
}

To toggle the visibility of these elements, we utilize the .ui-article[data-active] CSS rule to dynamically adjust their appearance.

.ui-article[data-active] {
    -webkit-transform: translateX(0%);
    transform: translateX(0%);
}

An additional CSS declaration, ui-article:before, adds an empty section for hiding the image description. This content becomes visible with the help of the .ui-article[data-active]:before CSS rule.

https://i.sstatic.net/SDCgD.png

To enable interaction with thumbnails and navigation buttons, the data-active attribute within the mentioned classes needs to be toggled appropriately. The thumbnail event handling function can be defined as follows:

function setThumbnailAction() {
  var uiThumbnailElements = document.getElementsByClassName("ui-thumbnail");
  var i, len = uiThumbnailElements.length, thumbnail;

  itemsInGallery = len - 1;

  for (i = 0; i < len; i++) {
    thumbnail = uiThumbnailElements[i];
    thumbnail.onclick = function() {
      key = this.dataset.key;
      showImage();
    }
  }
}

This function retrieves the thumbnail key value, stores it in a global variable 'key', and then triggers the showImage() function.

In the showImage() function, we manipulate the data-active attribute to control the visibility of elements with CSS classes ui-big-image, ui-article, and ui-thumbnail, based on the current 'key' value obtained through the selector

div.ui-big-image[data-key=\"" + key + "\"]
. Initially, we clear the data-active attribute using the restoreGallery() function.

function showImage() {
    restoreGallery("ui-big-image");
    restoreGallery("ui-article");
    restoreGallery("ui-thumbnail");
    var image = document.querySelector("div.ui-big-image[data-key=\"" + key + "\"]");
    image.dataset.active = "true";

    var article = document.querySelector("article.ui-article[data-key=\"" + key + "\"]");
    article.dataset.active = "true";

    var uiThumbnail = document.querySelector("div.ui-thumbnail[data-key=\"" + key + "\"]");
    uiThumbnail.dataset.active = "true";
}

The functionality can be previewed in action through these examples:

Using pure JavaScript:

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

CSS Element Overlapping Issue in Safari Browser

I am currently developing an audio player for my application that includes a pause/play button, next button, and back button. I have encountered a problem specifically on Safari where the back/pause buttons are overlapping each other. The play/pause button ...

Is it acceptable to debut a full-screen iframe widget compared to an embedded one?

My current project involves integrating a custom widget into users' websites for my application. I am considering using an iframe as it seems to be the most efficient option for several reasons: Utilizing the custom framework of the application will ...

Maximizing the functionality of a datetime picker with dual validators

I have successfully implemented a Date time picker on my website. Everything is functioning properly, but I am looking to apply two validators: one to disable Saturday and Sunday, and the other to exclude US holidays. Below is the function I am currently u ...

Utilizing Javascript to make multiple API requests to fetch data from Youtube

Currently, I am attempting to create a JSON object that represents the views per video for a specific YouTube user. To achieve this, I start by making an API call to retrieve all the video IDs from a designated channel, storing them in an empty array. Sub ...

Trigger an alert when a button is clicked and redirect the user to an newly opened tab

I recently created a button with a link that opens in a new tab. I also implemented some JavaScript to display an alert. Everything is working as expected, but after the user clicks "OK" on the alert, they remain on the same page. I would like to automati ...

Is there a pub/sub framework specifically designed for managing events in Angular?

Having a background in WPF with Prism, I am familiar with the IEventAggregator interface. It allows you to define events that can be subscribed to from controllers and then triggered by another controller. This method enables communication between controll ...

Ensure that all floating divs have uniform height

How can I ensure that two divs placed side by side will always have the same height, even when one of them changes based on content, using only CSS? I created a fiddle to demonstrate. I want both the red and blue divs to have equal heights... http://jsfi ...

Can someone please advise me on how to output the value of a var_dump for an array using console.log?

After writing the code in this manner, it functions properly and returns a JSON object. public function getElementsAction() { $currency = App::$app->getProperty('currency'); if(!empty($_POST)) { $sql = 'SELECT name, p ...

The issue persists with the MVC Controller parameter returning as null consistently, especially when the object field is

When using JavaScript to call a controller and process a function, I encountered an issue where the parameter value (name in summary) is null when the field is set to private. However, the function works correctly when the field is set to public. Is settin ...

Is it possible to display the <input type="text"> and the following <div> element on the same line instead of having space between them?

Could you please advise on how to adjust the layout to eliminate the space between the input type="text" and the following div element? When I set the width of the input type="text element to 180px and the width of the subsequent div to 20px, the div overf ...

What is the process for obtaining a new token in a Linnworks embedded application?

I decided to share my issue on this platform since the support from Linnworks is virtually non-existent. My dilemma involves a private embedded app created within Linnworks that showcases orders in spreadsheet format. The app, constructed using Vue.js and ...

Seeking assistance with creating a custom function to organize arrays within an object

I'm currently attempting to organize an Object that contains only properties which are arrays. My goal is to sort these arrays based on their length in order to ensure that when using Object.keys(), the resulting list will display all names in the cor ...

Inheriting Django templates for a unique CSS class markup approach

I want to create a master.html file for inheritance, but I'm facing an issue where the code is repetitive in three different places except for the body class. Here's my current master.html: <html> <head>...</head> <body& ...

The Express server is able to generate a 304 response within a quick 500ms timeframe

I currently have a basic express server setup. It includes the use of compression and serves files using static-serve. The cacheControl is set to false, relying only on ETag. When the server returns a 304 for the files (as intended), it takes around 500ms ...

HTML/Angular tutorial: Sharing an On-Click value with a different HTML element within the same component

As a newcomer to this, I could really use some guidance. Currently, I have a Mat Table that is displaying a specific range of data from my firestore. My goal is to be able to click on a particular row and have its data appear in a list below the table. I ...

Maintaining selected options in select lists while updating model data in Angular

New to Angular and exploring the Product object with Sku objects nested inside. An app allows users to fetch a product, resulting in the Product object being assigned to $scope.product: var app = angular.module('app', []); app.controller(&apos ...

preventing CSS hover effects

One of the CSS classes I have defined is for a button, which looks like this: .MyButton{ color:black; background:white;} .MyButton:hover{ color:white; background:black;} This class is used for pagination buttons. When a button reaches its bounds, I ...

Troubleshooting: Bootstrap 5 Alert not Displaying on Website

I'm experiencing an issue trying to display a bootstrap alert in my HTML code. Here is the code I'm using: <div class="alert alert-success alert-dismissible fade show" role="alert"> text & ...

Trouble with centering the footer bar at the bottom using CSS

Hi everyone, I'm having trouble centering my bottom bar on the screen. <style type="text/css"> body { background: #fffff; margin: 0; padding: 0; font: 10px normal Verdana, Arial, Helvetica, sans-serif; } * {margin: 0; padding: 0; outline: non ...

Navigating JQuery's Append and After functions can be a challenge

Struggling to make my simple input line append whatever is entered when the OK button is pushed. Despite trying various methods, I can't seem to get it working properly. HTML: <p> <input name="todo" id="todo" type="text" value="Set Me To Val ...