


How can I create responsive horizontal page sliding using jQuery for a website with varying heights?
Horizontal Responsive Page Sliding
To design a responsive page navigation similar to the provided image, consider the following jQuery solution:
- Calculate Dimensions: Determine the number of slides, set the wrapper width, and set each slide's width accordingly.
- Slide Animation: Bind a click event to navigation links that animates the wrapper's left-margin to reveal the corresponding slide.
- Active Link: Toggle the "selected" class for the clicked link to highlight the active page.
This approach ensures that the navigation adapts to screen size and handles pages with varying heights, eliminating gaps. Additionally, it utilizes a single menu occurrence to minimize markup and supports a dynamic number of slides.
<code class="js">$(document).ready(function () { var slideNum = $('.page').length, wrapperWidth = 100 * slideNum, slideWidth = 100 / slideNum; $('.wrapper').width(wrapperWidth + '%'); $('.page').width(slideWidth + '%'); $('a.scrollitem').click(function () { $('a.scrollitem').removeClass('selected'); $(this).addClass('selected'); var slideNumber = $($(this).attr('href')).index('.page'), margin = slideNumber * -100 + '%'; $('.wrapper').animate({ marginLeft: margin }, 1000); return false; }); });</code>
<code class="css">html, body { height: 100%; margin: 0; overflow-x: hidden; position: relative; } nav { position: absolute; top: 0; left: 0; height: 30px; } .wrapper { height: 100%; background: #263729; } .page { float: left; background: #992213; min-height: 100%; padding-top: 30px; } #page-1 { background: #0C717A; } #page-2 { background: #009900; } #page-3 { background: #0000FF; } a { color: #FFF; } a.selected { color: red; } .simulate { height: 2000px; }</code>
<code class="html"><script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <div class="wrapper"> <nav> <a href="#page-1" class="scrollitem selected">page 1</a> <a href="#page-2" class="scrollitem">page 2</a> <a href="#page-3" class="scrollitem">page 3</a> </nav> <div id="page-1" class="page"> <h3>page 1</h3> <div class="simulate">Simulated content heigher than 100%</div> </div> <div id="page-2" class="page"> <h3>page 2</h3> <div class="simulate">Simulated content heigher than 100%</div> </div> <div id="page-3" class="page"> <h3>page 3</h3> <div class="simulate">Simulated content heigher than 100%</div> </div> </div></code>
The above is the detailed content of How can I create responsive horizontal page sliding using jQuery for a website with varying heights?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



If you’ve recently started working with GraphQL, or reviewed its pros and cons, you’ve no doubt heard things like “GraphQL doesn’t support caching” or

With the recent climb of Bitcoin’s price over 20k $USD, and to it recently breaking 30k, I thought it’s worth taking a deep dive back into creating Ethereum

No matter what stage you’re at as a developer, the tasks we complete—whether big or small—make a huge impact in our personal and professional growth.

It's out! Congrats to the Vue team for getting it done, I know it was a massive effort and a long time coming. All new docs, as well.

I had someone write in with this very legit question. Lea just blogged about how you can get valid CSS properties themselves from the browser. That's like this.

I'd say "website" fits better than "mobile app" but I like this framing from Max Lynch:

There are a number of these desktop apps where the goal is showing your site at different dimensions all at the same time. So you can, for example, be writing

The other day, I spotted this particularly lovely bit from Corey Ginnivan’s website where a collection of cards stack on top of one another as you scroll.
