"Enhance Your Website with a JavaScript Slide Feature, Hidden Text Animation,

I've encountered some issues with my code: HTML:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <script class="jsbin" src="js/jquery.min.js"></script>
        <link href="css/stylesheet.css" rel="stylesheet" type="text/css" />
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Bellevue</title>
    </head>

    <body>
    <div id="container">
        <div id="gallery">
            <center>
            <div id="slider">
              <img src="images/1.jpg">
              <img src="images/2.jpg">
              <img src="images/1.jpg">
            </div>
            </center>
            <div id="nav">
            <ul>
              <li class="active">Go to slide 1</li>
              <li>Go to slide 2</li>
              <li>Go to slide 3</li>
            </ul>
            </div>

            <div id="info">
              <div class="info"><h3>Info panel 1</h3></div>
              <div class="info"><h3>Info panel 2</h3></div>
              <div class="info"><h3>Info panel 3</h3></div>

            </div>
        </div>
    </div>
    <div id="lengte"></div>
    <script>
    var imgN = "95%";
    var galW = $('#gallery').outerWidth(true);
    var galL = $('#lengte').outerWidth(true);

    $('#slider, #info').width(galW*imgN);

    $('#nav li').click(function(){
      var ind = $(this).index();
      $('#slider').stop(1).animate({top: '-'+galL*ind },1500);
      $('#info').stop(1).animate({left: '-'+galW*ind },1500);
      $(this).addClass('active').siblings('li').removeClass('active');
    });
    </script>

    </body>
</html>

CSS:

@charset "utf-8";
/* CSS Document */

*{
    margin:0px;
}

  body{
    font-family:Arial, Verdana, Helvetica, sans-serif;
    background-color: #FFF;
    margin:0px;
    padding:0px;
  }

#container{
    margin-left:5%;
    margin-right:5%;
}

/*slider*/
  article, aside, figure, footer, header, hgroup, 
  menu, nav, section { display: block; }


  #gallery{
    width:100%;
    height:490px;
    position:relative;
    margin:20px auto;
    background:#eee;
    overflow:hidden;
  }
  #slider{
      width:680px;
      margin-left:auto;
      margin-right:auto;
      position:absolute;
  }
  #slider img{
    position:relative;
    float:left;
  }
  #lengte{
      width:350px;
  }
  #nav{
    width:100%;
    z-index:2;
    position:absolute;
    top:305px;
    text-align:center;
  }
  #nav li{
    cursor:pointer;
    display:inline;
    background:#ddd;
    padding:10px;
    margin:1px;
    border-bottom:1px solid #999;
    -moz-border-radius-topleft: 6px;
    -moz-border-radius-topright: 6px;
    -moz-border-radius-bottomright: 0px;
    -moz-border-radius-bottomleft: 0px;
    -webkit-border-radius: 6px 6px 0px 0px;
    border-radius: 6px 6px 0px 0px; 
  }
  #nav li.active{
    background:#eee;
    border-bottom:1px solid #eee;
  }

  #info{
    position:absolute;
    top:350px;
    height:140px;
    width:100%;
    background:#eee;
  }

  div.info{
    position:relative;
    float:left;
    padding:10px 25px;
    height:120px;
    width:100%;
  }

Issues:

  1. The images slide vertically, but they are not centered.
  2. Text disappears when sliding from right to left and I cannot see them. The next picture is displayed instead.
  3. The whole page is not positioned at the top, there is white space visible on top of the page.

Could someone assist me with resolving these problems?

View links here:
http://jsfiddle.net/FYgE5/

Answer №1

To address the initial issue, make sure your slider is wrapped in a 'window' div to display one image at a time. The wrapper div should be centered, not the individual slides themselves.

<div class="slider-wrapper">
    <div id="slider">

Remove:

<center>...</center>

CSS for the above:

.slider-wrapper {
    position: relative;
    width:680px;
    margin: 0 auto;
}

Additionally, eliminate padding from the navigation ul to prevent it from shifting off-center:

#nav ul {
    padding: 0;
}

To ensure the #info element stays on the page while sliding, enclose it within a wrapper div:

<div class="info-wrapper">
    <div id="info">

CSS for the above:

.info-wrapper {
    position: absolute;
    top:350px;
    height:140px;
    width: 100%;
}
#info {
    position:absolute;
    top: 0px;
    left: 0px;
    width: 300%;
    background:#eee;
}
div.info {
    float:left;
    padding:10px 0;
    height:120px;
    width: 33.33%;
}
div.info h3 {
    padding:0 25px;
}

To remove the top margin, delete margin-top from #gallery:

#gallery {
    margin: 0 auto 20px;

Final result:

http://jsfiddle.net/FYgE5/8/

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 could be causing my Express API registration route to fail when attempting to POST?

Currently, I'm in the process of developing a compact authentication system for a practice project that I've undertaken. As part of this endeavor, I am sending POST requests via Postman to my Express server located at http://localhost:4000/api/re ...

Showing videos on Django Template: Link to Media

Struggling to retrieve a video from a model as the correct URL is not being found even after adding the media directory in front of it. Is the method I am using to pull the URL from the model accurate? Check out the Code, Generated HTML, and Console log ...

I have a JavaScript code that smoothly scrolls to different id's on a webpage, but I need assistance in adding an exception for a particular id

I'm looking to incorporate smooth scrolling for all hash links in my JavaScript. However, I need the id=nav and its resulting hash link, /#nav, to be exempt from this functionality as it interferes with the menu responsiveness. Can someone provide gui ...

The function toggleClass() is malfunctioning

The .toggleClass() method seems to only be adding the "class" attribute to my selection, resulting in: <div id="toggle" class> ... rather than: <div id="toggle" class="on"> ... I've been trying to solve this issue for about 2 hours now ...

Using double quotation marks in Node.js to enclose variables

How do I pass variables from a post route redirect to a get route in Express? Thank you for your help. router.post("/message", function(req, res) { var email = req.body.email; res.redirect(`/passingemail/${email}`); }); //I want to retrieve the ...

Can someone please explain the functionality of "next()" in middleware and how it operates?

Currently, I am following a tutorial by Net Ninjas on node.js and attempting to create my own examples to solidify the concepts in my mind. For reference, I refer to the GitHub source code available on their profile. However, I have encountered an issue at ...

Ways to change the chart type in ApexCharts

I'm seeking a way to change the chart type of an existing ApexCharts that has already been rendered. After reviewing the methods, I attempted to use the updateOptions() method, but encountered the error: Uncaught TypeError: Cannot read property &apos ...

Placing a hyperlink within template strings

Currently, I am working on implementing a stylish email template for when a user registers with their email. To achieve this, I am utilizing Express and Node Mailer. Initially, my code appeared as follows: "Hello, " + user.username + ",&bs ...

Navigating through unidentified json keys using jquery

I've encountered an issue with a JSON object where the key can change, making it difficult to access data using specific key names. My goal is to display this data in a table format. For example, I may receive data like this: [{"domain":"animals","c ...

The process of setting up a carousel for tables using jQuery

I can successfully implement jquery for an image carousel, but now I need to find a way to create a sliding table format. Any assistance on this matter would be greatly appreciated. Here is the code I currently have: <ul> <li><a style= ...

Vue Mutation IndexOf returns a value of -1

Hey everyone! I'm facing a challenge with deleting a "product." Although the product is successfully removed from the database, I'm encountering an issue with removing it from the VuexStore array of products. Here's what I've tried so f ...

Multer can handle the uploading of various files from multiple inputs within a single form

I've searched everywhere on the internet, but I can't seem to find a solution that matches my specific issue. As someone new to Node.JS, I'm attempting to upload two different pictures using Multer from the same form. Here's what my for ...

Setting up RTL (Right to Left) functionality in Material UI version 5 - A Step-by-Step Guide

After updating my app to version 5 of Material-UI from version 4, I noticed that the RTL support is no longer functioning. I carefully followed the instructions in the documentation: https://mui.com/guides/right-to-left/ The current outcome is that the ...

Tips for maintaining visibility of the selected option within a dropdown menu

When I choose one item from a dropdown list of 3, the selected item is still visible in the dropdown along with the other two. I would like all three items to be displayed even if one is selected. reference dropdown Based on the reference image, even thou ...

JavaScript unable to access elements during page loading

I am facing an issue with the following code: var coll = document.getElementsByClassName("collapsible"); var i; for (i = 0; i < coll.length; i++) { coll[i].addEventListener("click", function() { this.classList.toggle("active"); v ...

Tips for patiently awaiting the completion of a fadeout function

After a fadeOut function completes, I want to update a value. Here is the function I am using: const fadeOut = (duration: number = 300) => { Animated.timing( opacity, { toValue: 0, dura ...

Having issues with the `font-weight` property in Chrome?

There was a recent test conducted on a certain element that showed perfect functionality on Firefox but did not respond as expected on Chrome when using the font-weight: bold/bolder property. An attempt was made to identify any other CSS property that mig ...

The QWebview is not rendering the HTML page correctly

I am currently working on a software project that includes a QWebView for displaying HTML files. However, I am facing an issue with the welcome page not displaying correctly. Instead of having an image between the red lines at the center, it appears unusua ...

What impact does async await have on the asynchronous nature of JavaScript?

Although JavaScript is synchronous, we utilize callback promises and async-await to achieve asynchronous behavior. However, with async-await, the code waits for the await statement to be completed before proceeding to the next statement, which may seem s ...

Steer clear of the null value in the subcomponent

There's a sub-component that I'm using for a page: <template> <div class="ll-page-wrapper"> <div class="ll-page-div"> <Page :total="data_count" :current="cur_page" @on-change="changePage"></Page> < ...