Issue with Image Transition while Linking

I have been attempting to create transitions between images using links. I followed the steps in 'Demo 6' from this page (http://css3.bradshawenterprises.com/cfimg/), but unfortunately, it did not work as expected on my testing website (danithemes.fanscity.eu/shugar). I have double-checked the code provided on the tutorial page, and it seems to be the same.

Below is the CSS code I am using:

p#cf7_controls {
  text-align:center;
}
#cf7_controls span {
  padding-right:2em;
  cursor:pointer;
}
#cf7 {
  position:relative;
  height:281px;
  width:450px;
  margin:0 auto 10px;
}
#cf7 img {
  position:absolute;
  left:0;
  -webkit-transition: opacity 1s ease-in-out;
  -moz-transition: opacity 1s ease-in-out;
  -o-transition: opacity 1s ease-in-out;
  transition: opacity 1s ease-in-out;
  opacity:0;
  -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";
  filter: alpha(opacity=0);
}

#cf7 img.opaque {
  opacity:1;
  -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=100)";
  filter: alpha(opacity=1);
} 

Here is the HTML code:

<div id="cf7" class="shadow">
  <img class='opaque' src="http://css3.bradshawenterprises.com/images/Birdman.jpg" />
  <img src="http://css3.bradshawenterprises.com/images/Birdman.jpg;" />
  <img src="http://css3.bradshawenterprises.com/images/Birdman.jpg;" />
  <img src="http://css3.bradshawenterprises.com/images/Birdman.jpg;" />
</div>
<p id="cf7_controls">
  <span class="selected">Image 1</span>
  <span>Image 2</span>
  <span>Image 3</span>
  <span>Image 4</span>
</p>

And the JavaScript code:

<script language="javascript" type="text/javascript">
$(document).ready(function() {
  $("#cf7_controls").on('click', 'span', function() {
    $("#cf7 img").removeClass("opaque");

    var newImage = $(this).index();

    $("#cf7 img").eq(newImage).addClass("opaque");

    $("#cf7_controls span").removeClass("selected");
    $(this).addClass("selected");
  });
});
</script>

My question is: Despite following the tutorial, what mistake am I making? Any insights would be greatly appreciated!

Answer №1

The issue lies within your HTML code:

<div id="cf7" class="shadow">
  <img class='opaque' src="http://css3.bradshawenterprises.com/images/Birdman.jpg" />
  <img src="http://css3.bradshawenterprises.com/images/Birdman.jpg;" />
  <img src="http://css3.bradshawenterprises.com/images/Birdman.jpg;" />
  <img src="http://css3.bradshawenterprises.com/images/Birdman.jpg;" />
</div>
<p id="cf7_controls">
  <span class="selected">Image 1</span>
  <span>Image 2</span>
  <span>Image 3</span>
  <span>Image 4</span>
</p>

You are using the same image "", which does not make sense. If you want to see a change, change the path for the other images.

<div id="cf7" class="shadow">
  <img class='opaque' src="http://css3.bradshawenterprises.com/images/Birdman.jpg" />
  <img src="http://css3.bradshawenterprises.com/images/X.jpg;" />
  <img src="http://css3.bradshawenterprises.com/images/Y.jpg;" />
  <img src="http://css3.bradshawenterprises.com/images/Z.jpg;" />
</div>
<p id="cf7_controls">
  <span class="selected">Image 1</span>
  <span>Image 2</span>
  <span>Image 3</span>
  <span>Image 4</span>
</p>

Remember to add this line in the HTML head section.

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

View it LIVE.

Answer №2

@Samantha provided the perfect solution. Simply swap out your current birdman image with a different one. I've created a code snippet on jsfiddle that demonstrates using the same image but with varying widths: http://jsfiddle.net/ssmith/abc123

<div id="cf7" class="shadow">
  <img class='opaque' src="http://example.com/alternate-bird-image.jpg" />
  <img src="http://example.com/alternate-bird-image.jpg" width="350" />
  <img src="http://example.com/alternate-bird-image.jpg"  width="250" />
  <img src="http://example.com/alternate-bird-image.jpg"  width="150" />
</div>

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

Dealing with unique constraint violation in Mongodb when using insertMany

Currently, I'm in the process of working on a project that involves using node.js and mongodb version 5. In my collection, I have implemented a unique index for the Parcel property. However, during testing, an error is triggered: MongoBulkWriteError: ...

The height of the textarea is too excessive

Just a quick question - in my HTML, I have a simple textarea nested within the body tags. Within my JavaScript, I am using jQuery to ensure that the body element is dynamically resized to match the height of the window: $(function() { $("body").heigh ...

Improving Performance in Vue by Reducing `$set` Usage

Sharing my code snippet below <div v-for="namespace in chosenNamespaces" v-bind:key="namespace.id"> <!-- Select the Parameter --> <select @change="updateParameter($event, namespace.id)" v-model="currParameterValues[na ...

The sum is being treated as a concatenation instead of an addition in this case

Why is the somma value showing the concatenation of totaleEnergetico and totaleStrutturale instead of a sum? RiepilogoCombinatoStComponent.ts export class RiepilogoCombinatoStComponent implements OnInit { constructor() { } interventi: AssociazioneI ...

What is the correct way to express an object in an array?

I've encountered an issue: I'm working with an array called _daysConfig<DayConfig> When I manually populate it like this, everything functions correctly: _daysConfig: DayConfig[] = [ { date: new Date('Wed Jul 22 2020 21:06:00 GMT+02 ...

What is the process for generating a fresh PSBT transaction using bitcoinjs-lib?

This is the code I've been working on import * as bitcoin from 'bitcoinjs-lib' const NETWORK = bitcoin.networks.regtest; const psbt = new bitcoin.Psbt({ network: NETWORK }); function p2shAddress(node: bitcoin.ECPairInterface): string { c ...

Encountering null injector errors when running ng test on an Angular application

I have successfully developed a webpage in my Angular application and it is running perfectly. But, when I run ng test, some errors are popping up in Karma like the one shown in the image below: https://i.sstatic.net/lUKS5.png superuser.component.ts // ...

The issue of CSS Grid not adapting fully to different screen sizes and

Recently, I took on a coding challenge from Frontend Mentor (this one) and managed to complete it successfully. However, the grid I designed is not fully responsive. It only adapts correctly when the page width matches the media query specifications. The c ...

Adjusting Flexslider to perfectly accommodate the height and width of the window dimensions

Currently, I am using Flexslider version 1.8 and seeking to set up a fullscreen image slider on my homepage. My goal is to adjust the slider to match the browser window size. While experimenting with width:100% and height:auto properties, I have managed t ...

Automatically redirect to the linked page once the video concludes

Would it be feasible for a html5 video to trigger the opening of a new page upon completion? What would be the approach to achieve this using javascript? ...

Everything runs smoothly when initiating the API call through npm start, but unexpectedly crashes upon attempting to

Here is an API call located at http://localhost:9000/testAPI. Within the bin/www file: var port = normalizePort(process.env.PORT || '9000'); app.set('port', port); Inside the routes/index.js file: var express = require('express&a ...

Coordinate the timing of CSS animation with the loading of the page

Despite the abundance of similar questions, none have quite addressed my specific query. I've created a preloader using CSS animation and I want it to synchronize perfectly with the page load. While I can trigger the animation on page load, I'm s ...

Execute JavaScript function in NodeJS server background

I have developed a function that periodically monitors the battery statuses of connected android devices and returns an array. How can I execute this function on server startup and ensure it continues to run while sharing its information with other pages? ...

Tips for updating the filename in a file input using AngularJS

Is it possible to dynamically change the name of a chosen file? For instance, if I select a file with the name "img1", can it be automatically changed to a different dynamic name upon selection? <input type="file" fd-input/> https://i.sstatic.net/d ...

The issue arises when trying to apply a JQUERY css class to a dynamically added div

Utilizing JQuery-1.6.2 and drag-and-drop plugins Below is the code snippet from webform1.aspx: $(document).ready(function() { $( ".draggable" ).draggable({ revert: "invalid" , helper: "clone" }); $( ".droppable" ).droppable({ activeClass ...

Trouble with serving CSS files using Express static directory

In my app.js file, I have the following code: app.use(express.static(path.join(__dirname, '../public'))); This code snippet is from my main layout page: <link rel="stylesheet" href="/css/styles.css"> Despite trying various combinations, ...

Unexpected Error with Background Position Variable

Hello, I am attempting to create an animated background effect that moves up and down using the .animate() and .hover() methods in jQuery. Within my DOM, there is a div with id="#menu" containing a UL list where each item has a background positioned at dif ...

Is there a way to run a node script from any location in the command line similar to how Angular's "

Currently, I am developing a node module that performs certain functions. I want to create a command similar to Angular's ng command. However, I am facing compatibility issues with Windows and Linux operating systems. Despite my attempts to modify the ...

Submitting a form from outside the form using a button in HTML: A step-by-step guide

I'm looking to submit a form using Angular on the functions next() and saveStep(). I'm unable to place next() and saveStep() within the form itself. I have set up my ng-click for next() and saveStep() below the form. When I submit the form fro ...

Changing a string to uppercase and lowercase

I am currently working on a software that takes a string, divides it, capitalizes the first letter of the first string, and capitalizes all letters in the second string. Below is the code snippet: var fullName = "ThEoDORe RoOseVElT"; function nameEditor( ...