"Discover the magic of sliding animations with JavaScript and JQuery

I have been working on creating a background slide show effect, but so far, I've only managed to make a basic slideshow without any attractive transition effects like sliding or fading. Can anyone provide advice on how to add these more visually appealing effects?

Here is the code I currently have:

HTML CODE

<!DOCTYPE html>
<html>
<head>
    <script type="text/javascript" src="jquery-2.1.0.js"></script>
    <script type="text/javascript" src="function.js"></script>
    <link rel="stylesheet" type="text/css" href="style.css">
</head>
<body >
        <div class='bannerbg'>
            <div class='slider'></div>
        </div>
</body>
</html>

CSS CODE

body{
    margin: 0px;
    margin-left: 0px;
}

.bannerbg{
background-size: cover;
position: relative;
height: 500px;

}

.bannerbg img{
    width: 100%;
}

.slider{
    width: 940px;
    height: 360px;
    background-color: #FFDF00;
    position: relative;
    margin: 0 auto;
    top: -370px;
}

JavaScript CODE

$(document).ready(init)

images=new Array
(
"img/1.jpg",
"img/2.jpg",
"img/3.jpg",
"img/4.jpg"
);  


function init(){
$('.bannerbg').prepend("<img id='principala' src='"+images[1]+"' />")
}

function left() // This function shifts the array index one place to the left
    {
        images.push(images.shift());
    }

function change(){
    p=document.querySelector("#principala");
    p.src=images[1];
}

setInterval("left(); change()",1000);

Answer №1

To achieve the sliding effect, I utilize the animate function along with defining the css property and setting the animation duration in milliseconds for the specified element. Here's an example:

jQuery( "#slid_img1" ).animate({marginLeft: 0}, 250);

The result is a smooth sliding transition. Consider incorporating the animate function into your code to create a similar sliding animation.

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

One or multiple web browsers set in the Browserslist of the project

I have recently started working with the Ionic framework and encountered some warnings while setting up my application. Can anyone help me with a solution? [ng] When starting the Ionic application, I received the following warnings: [ng] One or more browse ...

What's the best way to reduce the dimensions of this container in order to align them next to one another?

https://i.sstatic.net/VHahe.jpg As a novice student in the world of coding with html and css, I have embarked on a project to create a website. However, I've encountered a minor issue... I'm looking to adjust the width of these boxes so they al ...

Distinguishing Between server.listen() and app.listen() in Google Apple Engine

I am currently working on a NodeJS + Express application. While running it locally, I have the following code: const port = 3001; server.listen(port, () => { console.log(`App listening on port ${port}`); }); However, when deploying to GAE, I switch ...

Selection of child elements using CSS selectors

I have the following HTML snippet and I want to target the second child with the class name "embed": <div class="embed-container">test</div> This is what I tried: .feature-row .threecolumns .caption:nth-child(2) { border: 1px solid red; ...

The custom tooltip is not being displayed as intended

I'm currently working on customizing tooltips in angularjs google charts. My goal is to display multiple series data along with some text within the tooltip, similar to the demo showcased here. Specifically, I aim to include the legend and title of th ...

I'm puzzled as to why I have to encode the path parameter twice in order for the REST call to properly handle special characters

I have a challenge with a REST call that fetches a product's ingredients using the product name as the path variable. I allow for any character to be used, and I know I need to use encodeURIComponent(name) to encode characters such as "/" to prevent m ...

"Utilizing Flexbox for a full-height column with an auto overflow feature

I'm looking to create a layout with a fixed header and footer, where the content in between always takes up the full height. I decided to use a three-row flexbox layout. However, I'm encountering an issue with the left content column not scrolli ...

"Here's a simple guide to generating a random number within a specified range

I have encountered a specific issue: Within an 8-column grid, I am attempting to randomly place an item with a random span width. While I have successfully managed to position the item and give it a random width, I am struggling with adjusting the width b ...

Detect the entry during gridview inline editing and perform the update

Whenever I attempt to edit a row using inline editing in a GridView and hit enter in the text editor, instead of updating the row it cancels the edit and returns to its original state. How can I prevent this behavior and use jQuery to submit the updates ...

Adding and removing images in a dynamic Jquery gallery

Having trouble creating a picture gallery with preview functionality. Whenever I click on a picture, the div clears but the new picture is not appended. Am I overlooking something? <div class="thumbnails"> <img onmouseover="preview.s ...

MUI Grid with Custom Responsive Ordering

Can I achieve a responsive grid layout like this example? Check out the image here I have already coded the desktop version of the grid: <Grid container spacing={2}> <Grid item sm={12} lg={6} order={{ sm: 2, lg: 1 }}> ...

showing various perspectives upon clicking

I am in the process of creating a simple website using Rails to enhance my learning experience. One feature I am striving for is the ability to switch between tabs without changing the URL. For reference, you can check out an example here: http://tympanu ...

Tips for unit testing an Angular Service that is primarily responsible for redirecting to an external page from the application

My service is responsible for redirecting to a separate login page since we are implementing login as a service. function redirectToMembership() { var returnURL = $location.host(); returnURL+="/#/Authorization"; $window.location.href=Environme ...

Error: Unable to access null properties while attempting to address Readonly property error by implementing an interface

Here is the code snippet I am working with: interface State { backgroundColor: boolean; isLoading: boolean; errorOccured: boolean; acknowledgment: string; } export class GoodIntention extends React.Component<Props, State> { ... onCli ...

Issue arises when CSS selectors do not function properly with absolutely positioned divs

I am experiencing an issue with my CSS code that is functional on CodePen but not on my actual website. I am attempting to target the .appraisals class for manipulating the background color of an opaque screen slider containing information. Despite using a ...

How can jQuery be used to target a specific class based on its inner value?

For instance, within a div of the same class, there are 6 "p" tags - some containing 'member' text and others not. I aim to use jQuery to select all "p" tags with 'member' as their inner text and apply an additional class to them. Here ...

Modify the active link color in a Bootstrap menu by adjusting the CSS

Hi, I'm experiencing an issue with my CSS Bootstrap menu. I am unable to change the active link color, meaning that when I click on a link and move my mouse pointer out of the area, the link background turns white. I would like it to remain transparen ...

When transferring files using formData via axios, the server is unable to interpret the data

`` In my quest to figure out how to send a file from a client using an input type=file to an API, I came across the suggestion to use formData. Following some examples I found, I implemented this approach, but upon checking the data on the server side, it ...

Misplace reference to object during method execution

Here's a simple demonstration of the issue I'm facing. The count function is supposed to keep track of the number of items returned from a query. However, my current implementation causes me to lose reference to the function when calling it from ...

Is there a way to modify the specified styling when using vanilla-extract globalStyle?

In my current React project, I am facing an issue with the CSS styles being applied globally to all elements within the body. I have a new component that I want to add without inheriting these global styles. Is there a way to exclude this particular compon ...