How can I create a jQuery marquee that scrolls from top to bottom rather than from left to right?

I am looking to create a marquee effect that scrolls from top to bottom, rather than the usual right to left direction.

I came across a code snippet online that utilizes jquery .animate, but I am having trouble modifying it to achieve the desired vertical scroll instead of horizontal movement.

jQuery(document).ready(function($) {
        var marquee = function() {
          var window_width = window.innerWidth;
          var speed = 12 * window_width;
          $('#marquee li:first').animate( {top: '-20px'}, speed, 'linear', function() {
            $(this).detach().appendTo('#marquee ul').css('', "100%");
            marquee();
          });
        };
        if ($("#marquee li").length > 1) {
          marquee();
        }
      });
html,
        body {
          margin: 0;
          padding: 0;
          width: 100%;
        }

        #marquee {
          background: #090;
          font-family: Arial, Verdana, sans-serif;
          color: #FFF;
          font-size: 12px;
          text-align: center;
          font-weight: bold;
          line-height: 20px;
          width: 1035px;
        }

        #marquee ul {
          width: 100%;
          height: 20px;
          position: relative;
          overflow: hidden;
        }

        #marquee li {
          width: 980px;
          line-height: 20px;
          height: 20px;
          position: absolute;
          top: 100%;
          left: 0;
          text-align: center;
          list-style: none;

        }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
        <div id="marquee">
        <ul>
            <li>test 1</li>
            <li>test 2</li>
          </ul>
        </div>

Answer №1

To make it function on Y instead of X, you'll have to replace the width with height and set a fixed or absolute position to span the entire window height.

$(document).ready(function($) {
  var marquee = function() {
    var window_height = window.innerHeight;
    var speed = 12 * window_height;
    $('#marquee li:first').animate( {top: '100%'}, speed, 'linear', function() {
      $(this).detach().appendTo('#marquee ul').css('', "100%");
      marquee();
    });
  };
  marquee();
});

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
}

#marquee {
  background: #090;
  font-family: Arial, Verdana, sans-serif;
  color: #FFF;
  font-size: 12px;
  text-align: center;
  font-weight: bold;
  line-height: 20px;
  width: 100px;
  position:fixed;
  top:0;
  bottom:0;
  left:0;
}

#marquee ul {
  width: 100%;
  padding:0;
  margin:0;
  height:100%;
}

#marquee li {
  width: 100px;
  line-height: 20px;
  height: 20px;
  position: absolute;
  top: 0px;
  left: 0;
  text-align: center;
  list-style: none;
  font-size:14px;

}

See a live demo here - https://jsfiddle.net/7sunt6fz/1/

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

Issue with navigation menu button functionality on mobile devices

Whenever I attempt to access my website on a small device, the bootstrap navbar is supposed to collapse. However, the button doesn't seem to be working. Any assistance would be greatly appreciated as this is the one issue I'm struggling with. I&a ...

Utilizing jQuery caching for POST requests

I've noticed that even after setting cache:false in a jQuery AJAX Post request, it doesn't include the additional random string. Could this be because post requests aren't cached? Appreciate your help on this. ...

Sending an array of arrays from JavaScript to a Spring MVC controller via AJAX

Having a bit of trouble with passing arrays within arrays. The first example below shows a simple array being passed successfully. However, when attempting to pass an array of arrays in the second example, it doesn't seem to work. Any suggestions on h ...

What is the best way to display a child component inside an iframe using Vue.js?

Looking to provide a live preview of an email before sending it out, I've opted to use an iframe to contain the preview and prevent style leaks. The goal is for the preview to update dynamically as the user fills out form details. How can I display a ...

Using React and Material-UI: Implementing button functionality to call another class using hooks in the main App component

Just starting out with React/MUI and currently working on different components for a website, so the UI is not a priority at the moment. Encountering an issue when trying to create a button that links to the Sign Up page (similarly for Sign In): Error: ...

Mark the term on the backspace key and remove it after pressing the second backspace button

<html> <body> <div id="textareaId" contenteditable="true"> Hello there </div> <button onclick=selectText(0,4)>Click to select</button> <button onclick=deleteSelectedText()& ...

Issue with Angular 2 page refresh is not triggering blur event

In our Angular 2 component, updates (HTTP PUT) are triggered when a user enters data and either tabs to the next field or hits enter. The event handling for this is set up using both blur and key.enter. Blur works efficiently as it is fired when the user ...

Utilizing AJAX with JSON for passing parameters

function FetchAndSerialize() { $.ajax({ type: "POST", url: "GetDataPage.aspx/SerializeData", data: "{}", contentType: "application/json", dataType: "json", success: function (r ...

Utilize JSON to populate data in a switch case scenario

I am attempting to implement switch cases using JSON. How can I load the data into the switch statement? Here is the desired output: $(".custom-menu li").click(function(){ switch($(this).attr("data-action")) { case "Science": $('.abc:e ...

Utilizing Bootstrap datepicker to set maximum and minimum dates based on another date input

I have been attempting to create a restriction on the date selection, where datepicker1 cannot exceed datepicker2, and vice versa. Initially, I tried implementing this feature using (Linked Pickers). Unfortunately, this did not achieve the desired date in ...

Issue with Nativescript tab view not functioning as expected

I have encountered a bug while manually trying to change tabs. The issue arises when the tab index changes but the tabs themselves do not update accordingly. In order to demonstrate this problem, I have created a NativeScript Playground app where you can ...

Is it possible to use key-value pairs as search criteria?

Is there a way to pass similar objects (which are simply data representations) within a search query? When dealing with single data, I can easily use: .com/search?id=2&value=test,test2 But what if I have multiple ids with different values like: { 2 ...

Is there a way to display a single div id from an external html file within a popup modal?

I have a dilemma with my external HTML content that is being displayed in a popup modal using an awesome library called jQuery Modal. Currently, the entire page displays perfectly within the modal, but I am aiming to only reveal one specific div each time ...

Guide to verifying a field's value in a database

My web application requires three inputs from the user: UserName, FirstName, and Email. The goal is to verify if the entered username exists in the database and if so, validate the corresponding Firstname and email. If all three values are correct, a succ ...

jQuery auto-suggest feature failing to display search results

Just to clarify, I have very little experience with JS, so my understanding is limited. Fair warning :-) I'm currently working on an autocomplete menu that retrieves data from a webservice. This webservice will return various types of elements (such ...

Discover internal hyperlink using user input and generate a click event for the anchor

Is there a way to use jQuery to locate internal links on a page based on user input and trigger a click event on the anchor tag? ...

Adjusting the view of an OpenLayers3 map to encompass various vector layers

My OpenLayers3 map includes an OSM Tile layer and one or more Vector layers. I have a function that allows me to zoom into a single layer successfully: vector.addEventListener("change", function() { map.getView().fitExtent(vectorSource.getExtent(), ma ...

Change the class when the scroll reaches the same letter block while moving up or down

Within this div, there is a horizontal list displaying all the alphabets. Below the list, there are blocks of names starting with each alphabet, with the header of each block matching the respective alphabet. I am looking to add a class to the div contain ...

Having trouble getting items to align properly in Bootstrap

As a student, I am struggling with my development skills while attempting to create a personal website. I am encountering difficulty aligning items on my rows in bootstrap. Here is what I am trying to accomplish: 1. However, I am currently stuck at this po ...

What is the best way to create a clickable button using HTML and CSS? The button should be centered on top of an image with a title

I'm in the process of creating a button overlay on an image that directs to another page within the same site. I don't have much experience with coding, but with some online resources, I was able to piece together what I needed. The issue I' ...