Adjust your orientation as you scroll

My desire is to change the position as I scroll down. To help visualize, here's what I have in mind:

https://i.sstatic.net/YYVmZ.gif

To view the code associated with this effect, click here

html :

<h1> MY TEXT. orem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. </h1>
<div class="one"> </div>
<div class="two"> </div>

css :

body {
  text-align:center;
}

h1 {
  left: 0;
  line-height:2;
  right:0;
  width:600px;
  margin-left: auto;
  margin-right: auto;
  position:fixed;
}

.one, .two {
  width:600px;
  position: absolute;
  left: 0;
  right:0;
  margin-left: auto;
  margin-right: auto;
}

.one {
    top:100px;
    height:300px;
    background:grey;
}

.two {
    height:800px;
    background:pink;
    margin-top:30px;
    top:400px;
}

Answer №1

Experiment with this technique using jQuery.

$(window).scroll(function () { 
     $(".element").offset({ left: newLeft, top: newTop});

});

adjust the offset values based on your specific requirements.

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

Is there an issue with this particular jQuery if condition?

This page aims to display various options based on the selection made in the dropdown. The toggle functionality is currently working correctly without the need for an if statement. How do I modify the if statement to perform the accurate comparison? < ...

The function trigger() in jquery is not functioning properly

Below is the code snippet provided: $(document).ready(function () { //alert("wa"); $("#wis").trigger('click'); $("#wis,#wib").click(function (){ alert("clciked"); if(!$(this).hasClass("dealsb")) { $(".dealb").removeCl ...

Adjusting canvas size to match content dimensions

I posed a similar inquiry and it was categorized as a duplicate even though the suggested duplicate did not provide an answer to my question. Edit: The purported duplicate was [stackoverflow.com/questions/17211920/make-canvas-height-auto][1] I am utilizi ...

Trying to select the first tab using jQuery. Unfortunately, the only method that seems to work is causing an error

Currently, I am attempting to automatically choose the initial tab using jQuery. The following method is successful: $('#tabs').tabs('option', 'selected', 0).trigger(); However, it results in a Firebug error related to the ...

Tips for incorporating data attributes into <figure> elements and retrieving them using CSS

Can we enhance a <figure> element by adding data attributes and then utilizing them in CSS? For example, I attempted figure { margin: 0 attr(data-margin %); } using <figure data-margin="15">...</figure> but it didn't yield the d ...

Choosing read-only text fields using JQuery

I am working on an ASP.NET MVC project and I am looking to select all text boxes with the "readOnly" attribute on the current page. Once identified, I want to trigger a modal jQuery dialog on keypress for each of these disabled text boxes. Any suggestion ...

Creating a fresh line using text interpolation within Angular 4 and Ionic 3

I am facing an issue with my front-end code: <p>{{ news.content }}</p> The variable news.content is stored in the Firebase DB. Is there a way to insert a new line in this text interpolation without making any changes to the front-end code (H ...

Using jQuery's .post() method to automatically scroll to the top of

Is there a way to prevent the automatic scrolling to the top of the page when executing the buy function? Here is the code snippet involved: <a href="#" onClick="buy(id)">Buy</a> The buy function utilizes the $.post() function for processing t ...

What is the best way to align my text to the top of a div, rather than the bottom?

Currently, the text is displaying at the bottom. This is my code snippet: <div class="container"> <h1 class="text-center">Machine Learning and Development</h1> <div style="text-align: left;"> <!-- <video autoplay mu ...

Displaying the structure of a MongoDB database using Express and Angular in a tabular format

I am looking to present the data from MongoDB in a table format using HTML along with Node.js, Express.js, and Angular.js. Currently, my approach is as follows: route.js app.get('/superhero', function(req, res) { superhero.superhero_list(r ...

Implement a CSS design for the flash notification

My application is built with Sinatra. I have implemented the sinatra-flash gem to display flash messages if the user fails to select enough items for comparison. While this functionality is working fine, I am having difficulty customizing the styling of th ...

Text spilling out from within Bootstrap cards

I created 4 Bootstrap cards, each in a separate column. Within each card, I added another card with some information. However, when I test the responsiveness by reducing the screen size, the text overflows out of the card. Can anyone help me understand wh ...

Is it feasible to arrange <DIV>s based on their dates?

I encountered an issue while working with an ordering function. var $wrapper = $('#list'); $wrapper.find('.blogboxes').sort(function (a, b) { return +b.dataset.date - +a.dataset.date; }) .appendTo( $wrapper ); <script src="ht ...

Button failing to align properly in the center position

I was able to successfully create a responsive input box, but for some reason, the button is not aligned in the center. Below is the CSS code: .webdesigntuts-workshop button { background: linear-gradient(#333, #222); border: 1px solid #444; border- ...

Opera does not support Ajax functionality

My ajax script is not functioning properly in Opera browser, although it works fine on other major browsers. $(function() { $("a").on('click', function(e) { var href = $(this).attr('href'); $.ajaxSetup({ beforeSend:fu ...

Implementing Pagination or Infinite Scroll to Instagram Feed

Currently, I am working on creating an Instagram feed for a fashion campaign where users can hashtag their photos with a specific tag. Using the Instagram API, the script will pull all recent posts with this common tag to display on the webpage. Instagram ...

How can you use jQuery.ajax to solely fetch the status code without downloading the entire document?

My application relies on the use of jQuery.ajax to check if a particular resource exists by constantly polling it. Once the resource is no longer returning a 404 status code, the app redirects to view that resource. However, I am concerned about downloadin ...

Navigating Through Siblings with Http Agility Pack

When it comes to working with the HTML Agility Pack, it's easy to extract descendants and entire tables. However, how can you utilize this tool in a unique situation like the example below? ...Html Code above... <dl> <dt>Location:</dt ...

"Is there a way to extract a specific value from an XML file based on another element

<dataset> <study recNO="0" seriesRecCount="1"> <patientID>123456</patientID> <accessionNumber>M120170428105320</accessionNumber> <patientIDID>35</patientIDID> <studyUID>2.25.1439 ...

What is the proper way to mention JavaScript packages when including them as parameters in Angular elements within HTML?

I was looking to enhance the command to be more authoritative. <div (click)="lastCall(999)">click me</div> My attempt to utilize Number.MAX_SAFE_INTEGER resulted in an error from my computer stating that it wasn't recognized. As a result ...