Guide on implementing a horizontal slide effect for background images

I am working on a mobile web application and I would like to create a homepage with an animated background image that slides like a portrait.

For example, if the mobile screen width is 360px and the background image size is 500px, I want the image to start at position 0 and slide automatically until it reaches 600px.

This idea was inspired by the Pegasus Airlines mobile app.

Could someone please provide guidance on how to implement this using CSS, HTML, and jQuery?

Answer №1

Once all the elements are set up, the next step is to implement the jQuery animate() method:

$(document).ready(function(){ $("#mycontainerID").animate({"background-position": "-300px"}, 2000,'linear'); });

Assuming that your background image is starting at the coordinates 0,0 and you wish the animation to run for 2 seconds.

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

Using jQuery to fill input fields automatically with a mouse click rather than using the keyboard

I found a solution that works great for my needs here $("#EmailAddress").keyup(function(){ $("#Username").val(this.value); }); Even though this solution works perfectly when entering values with the keyboard, it doesn't seem to function properly ...

Is there a way to ensure a div remains responsive when placed inside another responsive div, without relying on media queries?

I'm having trouble creating a responsive square div with another responsive div inside it. No matter what I try, I can't seem to get it right without using media queries. I must be missing something, but I can't figure out what it is. Here& ...

Unable to populate SQL Server database from PHP JQuery form

I am facing an issue where hitting save just refreshes the page with a different URL added. Uncertain if it's due to my query or if the form data is not being submitted correctly. require_once ('connectionstring/connectionstring.php'); $con ...

Remove entry from database without needing to refresh the page with PHP

I've encountered an issue with my HTML and PHP code. Below is the code snippet: HTML <a href="deleteData.php?id=<?php echo $value['id']?>"><button name="delte" class="btn">Delete</button></a> deleteData.php ...

What is the best way to showcase a value in JavaScript using CSS styling?

I'm looking to customize the background, font style, and outline for both open and closed elements in the code snippet below: a.innerHTML = "We are Open now now."; a.innerHTML = "We are Closed, arm."; Additionally, I want to appl ...

Why isn't the virtual directory in IIS 7 pointing to the root website?

I need to set up a virtual directory in IIS 7 that will point to the root of a website on our server. Here is an example of the structure: Websites: | --- AssetsServer | - /images/ | - /css/ | - etc. | --- demoserver ...

Are Windows Gadgets the Next Big Testing Ground?

Are there any tools or resources that offer a console, error logging, etc. for testing Windows Gadgets? I've looked around but haven't had any luck finding something like this. Appreciate any help you can provide! ...

Bootstrap navigation bar collapsing horizontally instead of vertically

My Navbar is collapsing correctly, but when I click the toggle icon after it's collapsed, the items appear in a horizontal row instead of the intended vertical block. I have checked the code on the Bootstrap 5 example page and tried to replicate it, b ...

Exploring the process of implementing a dynamic background image feature in Vue

Looking to create a dynamic navbar and change its background image. I attempted the following: Here is my attempt: <b-navbar toggleable="lg" v-bind:style="headerStyle"> this.headerStyle = { backgroundImage: &a ...

How can I extract and display chosen values from multiple dropdown menus in designated text boxes based on their unique identifiers?

A website for evaluating car values is in the works, using a combination of PHP, MYSQL, JQUERY, and JavaScript. The database includes 3 tables: Table "car_make": id make 1 BMW Table "model": model_id model_name make_id 1 M3 1 Table "ca ...

Transmitting an array via Ajax

Is there a way to pass an array from JavaScript to PHP using Ajax? var selectedCheckboxes = $('.def-mask :checkbox:checked').serialize(); $.ajax({ url: 'ajax/battle.php', type: 'post', data: { playerReady: 1, atta ...

Issue with Bootstrap 5 collapse not toggling back on second button press

I am encountering an issue with a button that is supposed to show a div on click using Bootstrap 5's "Collapse" class. The problem is that the content shows up correctly on the first click, but it doesn't hide again when the user clicks the butto ...

Tips on generating an HTML element using JavaScript and storing it in a MySQL database

I need help with saving a created element to the database so that it remains on the page even after refreshing. Any assistance would be greatly appreciated. Thank you. document.getElementById("insert").onclick = function(){ if(document.getElementById( ...

Display the percentage difference between the current point and the previous point on a line graph using jQuery Flot

I'm working with a line graph in flot and I want to display the percentage change from the previous point above each data point. I've searched through the documentation, but I couldn't find any information suggesting that this feature is sup ...

Resolving a CSS Layout Dilemma: How to Overlay Sidebar on Wrappers

I've run into a challenge while attempting to position a sidebar over page wrappers. The issue with absolute positioning arises when the sidebar needs to align with the corner of the blue header. I have contemplated using JavaScript to maintain its cu ...

After clicking, revert back to the starting position

Hey there, I have a question about manipulating elements in the DOM. Here's the scenario: when I click a button, a div is displayed. After 2 seconds, this div is replaced by another one which has a function attached to it that removes the div again. ...

Clicking an element to uncover more information

Currently, I am working on solving the second question within this series of problems. The task involves creating a functionality where clicking on a legislator's name displays additional information about them. You can view my progress so far by visi ...

"Include a song in a playlist without the need to sign in - Spotify API

I am looking to create a playlist where users on my website can collaborate, even if they are not logged into Spotify. I want these users to have the ability to add songs to the playlist. Below is the Ajax code snippet that I have: $.ajax({ dataType: &a ...

Display content from Angular 5 template directly in table without using parent template

Despite the fact that this question has been raised multiple times, I find myself in a slightly tricky situation. Here is the structure of my table: <table> <th>...</th> <app-custom-rows *ngFor="let t..." [customAttribute]="someval ...

JavaScript - The AJAX response is consistently after being undefined

I am encountering an issue with the following functions: function get_non_authorized_bulk_edit_option_values() { var modificable_column_names = get_write_user_values(); alert(modificable_column_names); } The above function is calling this ...