Enhance your user experience by implementing a jQuery solution that makes a div

Looking to add a small div on the right side of your screen that moves along with your vertical window slider? Wondering if jQuery has a function to get the current vertical slider position?

I thought scrollTop() might work, but it only returns from a specific element. Here's what I have:

code

Check out this example on JSFiddle.

Answer №1

$(window).scroll(function(e){
  var scrolled = $(this).scrollTop();
  var bodyHeight = $('body').height();
  var topPercent = ((bodyHeight / scrolled) * 100) + 'vh';

  $('#btn').css('top', topPercent );

});

Determine the scroll distance of the window, calculate the percentage relative to the body height, and adjust the position using position: fixed and top: {scrolledPercentage}vh.

I haven't tested this yet, but this is how I would tackle it!

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

Unexpected event triggering

I have come across a snippet of code that allows me to retrieve URL query strings var QueryURL = function () { var query_url = {}; var query = window.location.search.substring(1); var vars = query.split("&"); for (var i=0;i< ...

The pattern() and onkeyup() functions are unable to function simultaneously

When trying to display a certain password pattern using regex while typing in the fields, I encountered a problem. The onkeyup() function works for checking if both passwords match, but it causes the pattern info box not to appear anymore. I'm curiou ...

Modify the collapse orientation in Bootstrap

I would like the button to expand from the bottom when clicked and collapse back down, instead of behaving like a dropdown. <head> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_ ...

"Experiencing issues with the Ajax search functionality, need assistance

I am working on a JavaScript code to create search suggestions for a music search engine. The issue I am facing is that when the first character is typed, everything works fine. However, if I type more characters, all the results are displayed in a singl ...

Include_once iterates

Is there a way to email myself the client's browser data just once? I am encountering an issue where the PHP seems to run every time an image transition occurs in a jQuery gallery on the page where the require_once is located. I attempted to prevent ...

Implement jQuery Tabs in Brackets software to enhance user experience

My Adobe Creative Cloud subscription is expiring soon, and I am considering switching to Brackets, an open-source code editor developed by Adobe. However, I am facing some difficulties adding jQuery tabs to my HTML documents. I downloaded the 1.10.4 zip f ...

CSS in flexbox nested with no overflow utilized

I have created a basic "table" layout using flexbox. I want to implement horizontal scrolling for a specific part of the table by using overflow-x property. When you look at the provided code snippet, you'll notice that the CSS styles are only visib ...

Is there a way to retrieve two separate route details using jQuery simultaneously?

Clicking the checkbox should display the Full Name: input type="text" id="demonum" size="05"> <button type="button" onclick="load_doc()">click</button><br><br> <input type="checkbox" id ="check" > The r ...

Feature of Thymeleaf: Download functionality

When working with my Thymeleaf template, I have successfully processed Java map content to HTML using the following code: <div th:each="file : ${files}"> <span th:text="${file.key}"></span> <!-- here file.key is retrieved --> ...

The process of converting a data:image base64 to a blob is demonstrated in this code snippet

Seeking a way to convert data:image base64 URLs to blob URLs. Below is the original code that generates the base64 URLs: <script> $(window).load(function(){ function readURL() { var $input = $(this); var $newinput = $(this ...

Manipulate data with Jquery Serialize

There are multiple text boxes, drop down menus, and radio options on this form. Upon clicking submit, I need to save all the information entered by the user in order to store it into a database. <div id="reg2a"> First Name: <br/><input type ...

Switch from jQuery modal to non-modal dashboard after logging in

Utilizing jQuery in a Zend Framework application. The login process occurs through the use of a nyroModal, a jQuery plugin sourced from . While everything functions as intended including validation, once the user successfully logs in and Zend_Auth records ...

How to make browsers refresh cached images

.button { background: url(../Images/button.png); } Issue: To improve performance, static content on the website is cached with expiration headers. However, when an image changes, users must manually refresh their browser cache (Ctrl+F5 in IE). ...

What is the best way to apply CSS to an image within a list item that is within an unordered list nested inside a specific

I've encountered an issue in my html file related to a navigation bar situated at the top of my page. The code snippet that initiates this navigation bar is as follows: <div class="“topNav"> <ul> <li><img src= ...

"Can the form and action occur on the same page, or should they be

When it comes to form actions, what is more effective: having the action on the same page or a different page? See the sample code below: <form action="act.php"> html code </form> <form action=""> html code </form> < ...

Text arranged in a vertical orientation with a group of text aligned along the baseline

I am trying to create the following layout: https://i.sstatic.net/HYNDw.png Here is what I need: The word total and the number 120 should align vertically in the center The words per month should align at the bottom with respect to the number 120 The ...

Adjusting the size and positioning of an image with CSS

Here is my situation: I am working with an image that is 1900 x 1600 pixels in size. I also have a div that is sized at 200 x 150 pixels. To adjust the image size, I used the following CSS: max-width:300px; max-height:300px; The height will be adjuste ...

Encountering a Syntax Error with Haxe while implementing jQueryExtern

Recently delving into Haxe and importing the jQueryExtern library, I encountered an issue while attempting to utilize the following code snippet: new JQuery(".roles:checked").each(function(){ }); This resulted in a compiler error message ...

Optical imaging-guided Page Division

Looking for guidance on implementing a program that can perform "Vision-based Page Segmentation" with practical information rather than just theoretical knowledge. I prefer using JS (jQuery) and PHP for this project. After reading the article on VIPS: a ...

Personalize your jQuery stack chart

I want to create a bar chart that plots users against work performance. I have been looking into using canvasjs.com to implement it as a stack chart, like shown https://i.sstatic.net/FdzRD.png However, I need to divide each section based on time. I am aim ...