Sliding a DIV using Jquery to occupy the top half of the page

I am attempting to create a functionality similar to what is found on Microsoft's Support Website. You can check it out here: (Visit Here)

By clicking on any product listed there, a drop-down menu appears. (Please note that the purpose of this article/question is not to market any product, but purely for educational purposes.)

After selecting an item from the menu, a new "Select a topic" list appears, and upon selection from this list, a third list is displayed. I am trying to replicate this functionality by creating a script. I have searched online and created a div slider, however, it slides the entire div. Below is the code that I have written:

HTML

<div id="gallery">
  <div id="slider">
     <div style="background:#cf5">1</div>
     <div style="background:#ada">2</div>
     <div style="background:#b0b">3</div>
  </div>
  <span id="prev">Prev</span>
  <span id="next">Next</span>
</div>

CSS

#gallery{
  position:relative;
  margin: 0 auto;
  overflow:hidden;
  width:500px;
  height:330px; /* +30 = space for buttons */
  text-align:center; /* to center the buttons */
}
#slider{
  position:absolute;
  left:0;
  height:300px;  
  text-align:left; /* to reset text inside slides */
}
#slider > div {
  position:relative;
  float:left;
  width:500px;
  height:300px;
}
#prev, #next{
  display:inline-block;
  position:relative;
  top:300px;
  cursor:pointer;
  padding:5px;
}

Jquery

$(function(){

    var $gal = $('#gallery'),
    $sli = $('#slider'),
    $box = $('div',$sli),
    W    = $gal.width(), // 500
    N    = $box.length,  // 3
    C    = 0;            // a counter

    $sli.width(W*N);

    $('#prev, #next').click(function(){
    C = (this.id=='next' ? ++C : --C) <0 ? N-1 : C%N;
    $sli.stop().animate({left: -C*W },800);
    }); 

});

For a working example of my code, you can visit Fiddle.

Answer №1

Upon conducting research and development, I was able to create something similar to the following:

HTML

<div>
        <input type="submit" id = "submit" value = "Show panel"/>
        <span id = "showpanel1"></span>
    </div>

    <div id = "slider"  style = "display:none">
        <div class = "panel1" style = "display:none">
            <ul>
                <li id = "divpanel0">Lorem ipsum dolor sit amet, consectetur adipiscing elit</li>
                <li id = "divpanel1">Pellentesque nec est eget eros placerat imperdiet sed ac purus.</li>
                <li id = "divpanel2">Fusce id dui lacinia, scelerisque dolor vitae, faucibus sem.</li>
                <li id = "divpanel3">Nulla dignissim odio non turpis consectetur malesuada.</li>
                <li id = "divpanel4">Ut vestibulum est quis lacinia sagittis.</li>
                <li id = "divpanel5">Maecenas interdum libero at suscipit iaculis.</li>
                <li id = "divpanel6">Donec in nibh sed lacus ultrices pellentesque sed in purus.</li>
                <li id = "divpanel7">Aliquam luctus eros id semper vestibulum.</li>
                <li id = "divpanel8">Donec vitae felis at leo rutrum mattis.</li>
            </ul>
        </div>

        <div class = "panel2" style = "display:none">
            <ul>
                <li id = "divpanel0">Lorem ipsum dolor sit amet, consectetur adipiscing elit</li>
                <li id = "divpanel1">Pellentesque nec est eget eros placerat imperdiet sed ac purus.</li>
                <li id = "divpanel2">Fusce id dui lacinia, scelerisque dolor vitae, faucibus sem.</li>
                <li id = "divpanel3">Nulla dignissim odio non turpis consectetur malesuada.</li>
                <li id = "divpanel4">Ut vestibulum est quis lacinia sagittis.</li>
                <li id = "divpanel5">Maecenas interdum libero at suscipit iaculis.</li>
                <li id = "divpanel6">Donec in nibh sed lacus ultrices pellentesque sed in purus.</li>
                <li id = "divpanel7">Aliquam luctus eros id semper vestibulum.</li>
                <li id = "divpanel8">Donec vitae felis at leo rutrum mattis.</li>
            </ul>
        </div>

    </div>


    <!-- Load Loder GIF -->


        <div id = "loader" style = "display:none">
            <img src = "loader.gif">
        </div>

    <!-- QnA Div Start -->

    <div id = "qaslider"  style = "display:none">
        <div class = "mainpanel" style = "display:none">
            <ul>
                <li id = "divpanel0">Lorem ipsum dolor sit amet, consectetur adipiscing elit</li>
                <li id = "divpanel1">Pellentesque nec est eget eros placerat imperdiet sed ac purus.</li>
                <li id = "divpanel2">Fusce id dui lacinia, scelerisque dolor vitae, faucibus sem.</li>
                <li id = "divpanel3">Nulla dignissim odio non turpis consectetur malesuada.</li>
                <li id = "divpanel4">Ut vestibulum est quis lacinia sagittis.</li>
                <li id = "divpanel5">Maecenas interdum libero at suscipit iaculis.</li>
                <li id = "divpanel6">Donec in nibh sed lacus ultrices pellentesque sed in purus.</li>
                <li id = "divpanel7">Aliquam luctus eros id semper vestibulum.</li>
                <li id = "divpanel8">Donec vitae felis at leo rutrum mattis.</li>
            </ul>
        </div>


    </div>

JS

<script src="js/jquery-1.9.1.js"></script>
  <script src="js/jquery-ui.js"></script>
  <script>  
    $(document).ready(function() {
         var firsttext;
         $(".panel1").on('click','li',function (){
            $(".panel2").show("slide", { direction: "right" }, 1000);
            $("span").text($(this).html());
            firsttext = $(this).html();

        });

        $('#submit').click(function() {
            $(".mainpanel").hide();
            $("#slider").show("slide", { direction: "right" }, 0);
            $(".panel2").hide("slide", { direction: "right" }, 0);
            $(".panel1").show("slide", { direction: "right" }, 1000);
        });

        $(".panel2").on('click','li',function (){
            $("span").text(firsttext + " > " + $(this).html());
            $( "#slider" ).fadeOut( "slow" );
            $("#loader").show("slide", { direction: "right" }, 800);
            $("#loader").center(true);
            setTimeout(removeslider,4000)
        });

    });

    function removeslider()
    {
        $("#loader").hide("slide", { direction: "left" }, 800);
        $("#qaslider").show("slide", { direction: "right" }, 0);
        $(".mainpanel").show("slide", { direction: "right" }, 1000);
    }
    // Custom jQuery Function to stop/place element at center screen

    jQuery.fn.center = function(parent) {
        if (parent) {
            parent = this.parent();
        } else {
            parent = window;
        }
        this.css({
            "position": "absolute",
            "top": ((($(parent).height() - this.outerHeight()) / 2) + $(parent).scrollTop() + "px"),
            "left": ((($(parent).width() - this.outerWidth()) / 2) + $(parent).scrollLeft() + "px")
        });
        return this;
    }

  </script>

Style

<style>
    .panel1 .panel1
    {
        border:1px solid black;
        margin-right:800;
        margin-top:20px;
    }
    #loader
    {
        margin-right:708;
        margin-top:117px;
        margin-left:525px;
    }
    .panel1 ul li:hover, .panel2 ul li:hover
    {
        cursor:hand
    }
    #slider > div {
      position:relative;
      float:left;
      width:500px;
      height:300px;
    }
  </style>

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

What is the best way to position the left sidebar on top of the other components and shift them to the

Currently, I am working on a project to display NBA data fetched from an API. I am aiming to recreate the design showcased here: Dribbble Design My main challenge lies in overlaying the left sidebar onto the main box and shifting the components sligh ...

Issue with data entry: unable to enter the letter 'S' in search field

This bug has been a real challenge for me. It's strange, but I'm unable to type the letter "S" into the search input field. Oddly enough, the keyboard seems to be functioning properly. Please find the sandbox below for reference: https://codes ...

The absence of the 'Access-Control-Allow-Origin' CORS header was noticed in the response from the Wikipedia API

Attempting to retrieve data from the Wikipedia API using axios in reactJS. Here is my request: axios.get('https://en.wikipedia.org/w/api.php?action=opensearch&search=lol&format=json&callback=?') .then((response) => { c ...

Using jQuery to verify the presence of an element, especially one that may have been dynamically inserted via AJAX

I have a good understanding of how to verify elements that are present when the document is loaded: jQuery.fn.exists = function () { return jQuery(this).length > 0; } However, this approach does not detect elements that are dynamically added via A ...

If the color of the border matches and the width of the border is equal to

As I navigate through multiple divs, my goal is to identify those with a distinct blue border. Furthermore, if a main div possesses a blue border, I need to check for any inner divs that also have a blue border or a border width of 3px. If the main div has ...

Guide on making a color legend with JavaScript hover effects

On my website, there is a dynamic element that displays a table when values are present and hides it when there are no values. The values in the table are color-coded to represent different definitions. I wanted to add hover text with a color key for these ...

Issue with Github actions: Failure in mark-compacts process due to ineffective operation near heap limit causing allocation failure - running out of memory in

Whenever I try to build my library files, I keep encountering an out of memory error. In my local setup, I was able to resolve this problem by executing the command export NODE_OPTIONS="--max-old-space-size=8192". Unfortunately, no matter how mu ...

What is the best way to organize objects by their respective dates?

I am retrieving data from a database and I would like to organize the response by date. I need some assistance in grouping my data by date. Below is an example of the object I have: var DATA = [{ "foodId": "59031fdcd78c55b7ffda17fc", "qty" ...

Tips on invoking the ('keyup') function within an AJAX request's success callback

I have been working on implementing a live search feature that is based on JSON data fetched through an AJAX call. Here is the code I have been using, but unfortunately, it is not functioning as expected. function returnVisitors(){ let output ...

Node.js does not support running Bootstrap and CSS, resulting in style not being applied due to the MIME type ('text/html') not being a supported stylesheet MIME type

I attempted to test out the Start Bootstrap Bare template using Node.js and Express. (Link to Start Bootstrap Template) I opted not to make any alterations to the HTML, CSS, and JavaScript files provided with the template. Instead, I created a new index.j ...

Displaying a plethora of data points on a single graph using jQchart with a

I'm currently using jQchart to showcase a graph, but I'm running into an issue with the title property only displaying a single line of text. The current title being displayed on the graph is as follows: text: chartTypeText + ': ' + ch ...

Leveraging OAuth 2 with Google

I'm currently working on implementing Google API for user authentication. I have successfully managed to authenticate users, but I am struggling with redirecting users after Sign In and implementing Sign Out functionality. I have been referring to th ...

Learn the technique of invoking a sub component's method from the parent component in Vue.js

I am looking to trigger a method in a sub component from the parent component in Vue.js in order to refresh certain parts of the sub component. Below is an example showcasing what I aim to achieve. Home.vue <template> <componentp></compo ...

What could be causing certain values within my array to appear as undefined?

Within my PHP code, I have a for loop that generates a series of checkboxes on the page with a specific format <input type="checkbox" name="checkbox[]"> My goal is to utilize JavaScript to identify which checkboxes are checked and store their value ...

Sending an array and an object simultaneously through a single ajax request

I previously inquired about passing an object to an ajax request for my rest service. Now I am wondering if it's possible to pass both an array and an object within a single ajax request. Any insights on this matter would be greatly valued. ...

What is the best way to transfer global Meteor variables to templates and effectively utilize them?

I am in the process of developing a compact, single-page application game that emulates the dynamics of the stock market. The price and behavior variables are influenced by various factors; however, at its core, there exists a finite set of universal varia ...

Does the CSS :not() selector function properly when used with distant descendants?

Check out the official documentation for the CSS3 :not() pseudo-class at this link: http://www.w3.org/TR/css3-selectors/#negation Additionally, you may be interested in the proposed enhancement for CSS Selectors Level 4 found here: http://dev.w3.org ...

Using React's higher order component (HOC) in TypeScript may trigger warnings when transitioning from non-TypeScript environments

I have a simple HOC component implemented in React with TypeScript. export const withFirebase = <P extends object>( Component: React.ComponentType<P> ) => class WithFirebase extends React.Component<P> { render() { return ...

When using Material UI TextField with input type "date", the event.target.value does not seem to be accessible

I am currently working with Material UI and React Grid from DevExtreme to build a table that includes an input field of type date. However, when I attempt to enter the date, it does not register the change in value until I reach the year field, at which po ...

Tips for positioning an asp.net Button alongside other elements in a form by making use of Bootstrap styling

Looking to revamp the style of my ASP.NET Web Forms project with the latest version of Bootstrap. Having trouble aligning an ASP.NET Button control horizontally with other controls in the form, as seen in this snapshot: https://i.sstatic.net/IVRKo.png Her ...