Is there a way to continuously cycle through multiple images fading in and out at various locations on a webpage using absolute positioning?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>

<title>Harley's Art Gallery</title>
<script type="text/javascript" src="js/jquery-1.6.2.min.js"></script>
<script type="text/javascript" src="http://stratus.sc/stratus.js"></script>


<style type='text/css'>
    #rotating-item-wrapper {
    list-style-type:none;
    margin:0;
    padding:0;
    height: 150px;
}  
.rotating-item-wrapper li{
    float: left;
    list-style-type:none;
    width: 148px;
    height: 150px;
    margin: 0 0 0 6px;
    padding: 0;
    position: relative;
    text-decoration: none;
}
.rotating-item-wrapper li div {  
    -webkit-border-radius: 5px;
    -moz-border-radius: 5px;
    border-radius: 5px;
}
.rotating-item{            
    display:block ;
    position: absolute;
    width: 148px;
    height: 150px;
}

.harleypaint {
...

<script type='text/javascript'>//<![CDATA[ 
$(document).ready(function(){
    var InfiniteRotator =
    {
        init: function()
        {
            //initial fade-in time (in milliseconds)
            var initialFadeIn = 3000;
            //interval between items (in milliseconds)
            var itemInterval = 1500;
            //cross-fade time (in milliseconds)
            var fadeTime = 3000;
            //count number of items
            var numberOfItems = $('.rotating-item').length;
            //set current item
            var currentItem = 0;
            //show first item
            $('.rotating-item').eq(currentItem).fadeIn(initialFadeIn);
            //loop through the items
            var infiniteLoop = setInterval(function(){
                $('.rotating-item').eq(currentItem).fadeOut(fadeTime);
                 var rand = Math.floor(Math.random()*(numberOfItems-1)) + 1;
            currentItem = (currentItem+rand) % numberOfItems;
                $('.rotating-item').eq(currentItem).fadeIn(fadeTime);
            }, itemInterval);
        }
    };
    InfiniteRotator.init();
});
//]]>      
</script>     

<style type='text/css'>
...

</html>

I'm designing a website for an artist named Harley, featuring a central Vimeo video surrounded by a menu. The minimalist aesthetic will be complemented by images of Harley working that will fade in and out around the video, creating a haunting effect.

I've encountered challenges with existing code for randomizing image displays without repetition. Most solutions lack the ability to position images dynamically. While exploring various approaches, I found that modifying absolute positions and timers for each image individually is cumbersome and limits the seamless loop.

I appreciate any insights or guidance on achieving the desired effect of smoothly transitioning images around the central video without repeating. Thank you for considering my request!

Answer №1

This is a simple script to get you started with cycling through an array of images, changing the source of an image tag, and adding some animation effects. It randomly selects a position on the page to fade the image in and out. http://jsfiddle.net/bhlaird/TH7t7/3/

JavaScript:

var images = [{
    src: "http://placeKitten.com/g/500/500",
    width: 500,
    height: 500
}, {
    src: "http://placeKitten.com/g/300/300",
    width: 300,
    height: 300
}, {
    src: "http://placeKitten.com/g/600/600",
    width: 600,
    height: 600
}, {
    src: "http://placeKitten.com/g/400/400",
    width: 400,
    height: 400
}, , {
    src: "http://placeKitten.com/g/200/200",
    width: 200,
    height: 200
}];


var counter = {
    val: 0,
    top: 0,
    left: 0
};

function getRandomInt(min, max) {
    return Math.floor(Math.random() * (max - min + 1)) + min;
}

function fadeImage(counter) {
    counter.top = getRandomInt(0, $("body").height() - images[counter.val].height);
    counter.left = getRandomInt(0, $("body").width() - images[counter.val].width);

    $("#haunting").fadeTo(2000, 0.3).delay(1000).fadeOut(2000);
    $("#haunting").attr({
        src: images[counter.val].src
    }).css({
        top: counter.top,
        left: counter.left
    });

    if (counter.val < images.length) counter.val++;
    else counter.val = 0;


}
setInterval(function () {
    fadeImage(counter);
}, 6000);

HTML:

<img id="haunting" style="display:none" src="http://placeKitten.com/g/500/200" />
<div id="video">
    <img src="http://placekitten.com/200/200" />
    <div id="menu">Some text</div>
</div>

CSS:

html, body {
    height: 100%;
}
#video {
    margin: auto;
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    width:200px;
    height:210px;
    text-align:center;
}
#haunting {
    position: absolute;
    top:0;
    left:0;
}

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

Adding Custom CSS File to an iFrame in Angular

Currently, I am attempting to include a CSS file in a third-party iframe to modify its styling. My initial idea was to employ the following code snippet: ngOnInit() { ... this.myIframe.nativeElement.document.head.appendChild('style.css') } U ...

Tips for designing a tilted CSS layout from scratch

I am looking to design a stylish interface using HTML & CSS. Here is the style I want to achieve: Currently, my interface looks like this: Although these are just reference images, you can see that my design does not have the same sleekness as the one in ...

Obtain asynchronous state in VueJS without the need for intricate v-if conditions

I am working on an application that heavily relies on Vue-Router and Vuex for state management. Within the Dashboard component, important user information is displayed. This data is fetched asynchronously from a database by Vue and then stored in Vuex. T ...

Accordion featuring collapsible sections

Looking to build an accordion box using Javascript and CSS. The expanded section should have a clickable link that allows it to expand even further without any need for a vertical scroll bar. Any ideas on how this can be achieved? Thank you ...

Display the Slug in the Website URL upon clicking on a Blog Post using Angular and Strapi framework

When a user clicks on a blog, I want the URL to display the slug instead of the ID. My frontend framework is Angular and I have created a service to fetch data from the backend built with Strapi. Currently, when selecting a blog from the view, the URL disp ...

Creating an event declaration using Javascript's onclick function

As I was getting ready to add an onclick event to my element in JavaScript, a question popped into my mind regarding the efficiency of these two options: document.getElementById(myid).onclick = function(e){...} or document.body.onclick = fun ...

JavaScript: Efficient method for converting currency values within an array

Hello everyone, I have come up with the code below to convert currencies, but the issue is that I am manually listing out each currency in a switch block. If I have a hundred currencies to convert, I would need to create a hundred switch cases. Is there a ...

What is the procedure for submitting all checkbox values through Google Apps Script?

My web app created using Google Apps Script can generate a custom table of data for users to select for calculations. I use Google Sheets to populate the table with values and checkboxes, but note that the table size may vary depending on the user. <fo ...

Issue with inner span not inheriting max-width set on outer <td> element

Whenever I hover over a table cell, the Angular Bootstrap popover should appear next to the text. However, the 'span' element remains at its full width. <td style="max-width: 50px; text-align: left; white-space:nowrap; overflow:hidden; text- ...

Unable to Pause Video with Javascript

I have a project with a video that plays in a continuous loop. Below is the HTML code for the video tag: <video playsinline autoplay muted loop id="myVid"> <source src="River.mp4" type="video/mp4"> </video> My goal is to make the vi ...

Exploring JSON Parsing in JavaScript

Upon processing the following JSON data: foobar({ "kind": "youtube#searchListResponse", "etag": "\"I_8xdZu766_FSaexEaDXTIfEWc0/pHRM7wJ9wmWClTcY53S4FP4-Iho\"", "nextPageToken": "CAUQAA", "regionCode": "PL", "pageInfo": { "totalResults": 68 ...

Unlocking Node.js packages within React JS is a seamless process

Currently, I am developing a React Serverless App with AWS. I am looking for ways to incorporate a Node JS specific package into the React JS code without requiring Node JS on the backend. One package that I need access to is font-list, which enables list ...

What is the best way to achieve a precision of 6 decimal places in JavaScript when working with decimals?

While working on coding to round numbers to six decimal places after performing some arithmetic operations, I encountered a problem. I was iterating through the elements of an array and conducting calculations based on the array contents. To achieve roundi ...

Jquery Mobile: Navigating back to the first page after calling changePage

In the process of developing a mobile app with phonegap/cordova and jquery mobile, I encountered an issue where the user is supposed to land on a specific page from a status bar notification. However, the app initially displays the default page briefly bef ...

Utilizing jQuery for toggling table rows to display or hide when replying

I am currently developing a message board system where users can post and reply to messages. Posting new messages is working smoothly, and I use AJAX to create a new table row for each message: <table id="content-table"> <tr> <th scope=" ...

"When setting up a window.EventListener, the Div element fails to be hidden when setting its display property to 'none

I'm working on creating a preloader by displaying an overlay until all the content on the page is loaded. However, despite checking my code multiple times, I can't seem to figure out why it's not working. If anyone could provide some assist ...

Having some trouble with my React and MUI project - the button animation isn't functioning as expected when clicked

After implementing a Button from MUIv5, I noticed that the full animation only triggers when I hold down the button instead of with a simple click. Is there a way to fix this so that the animation fully plays with just a single click? Any help is apprecia ...

Exploring prototypal inheritance through Angularjs module.service设计(Note: This

Having worked with Angularjs for a few months now, I am curious about implementing efficient OOP within this framework. Currently, I am involved in a project where I need to create instances of a "terminal" class that includes constructor properties and v ...

Using node.js with express to send data stored in a variable to the browser instead of displaying it in the

I'm currently getting the hang of node.js. It's pretty straightforward to use res.send and output some basic "hello world" text, but how can I pass variables to the browser instead of just to the console? Here is a snippet of code: var Tester = ...

Notification with jQuery

I am looking to display an alert message when val = -1. However, the issue I am facing is that this message always appears at the bottom of the page regardless of the value of val. if ($val == -1) echo ' <script> $( ...