


How to Create a Responsive Horizontal Page Sliding System with jQuery and CSS?
Responsive Horizontal Page Sliding
Problem
Designing a responsive horizontal navigation system presents several challenges:
- Maintaining page visibility within the viewport
- Preventing gaps or overlaps between pages
- Allowing for pages that extend beyond 100% height, with scrollbar visibility
- Ensuring compatibility with Internet Explorer 9 or above
Solution
This solution employs jQuery and includes the following key features:
- Responsive Sizing: The script calculates the total width of the wrapper based on the number of pages, ensuring responsive scaling.
- Smooth Transition: Clicking navigation links smoothly animates the wrapper's left margin, transitioning between pages without abrupt jumps.
- Dynamic Height Handling: Pages can extend beyond 100% height, and a scrollbar appears when necessary, eliminating unwanted gaps.
- Active Link Indication: The selected navigation link is highlighted to indicate the current page position.
- IE Compatibility: The code is compatible with Internet Explorer 9 and above.
Code Implementation
<code class="javascript">$(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>
CSS
<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>
Conclusion
This code snippet provides a comprehensive solution for responsive horizontal page navigation, efficiently addressing the stated requirements. Its flexibility allows for dynamic navigation menus and accommodating long pages with scrollbars. Moreover, its compatibility with Internet Explorer 9 ensures compatibility with a wide range of browsers.
The above is the detailed content of How to Create a Responsive Horizontal Page Sliding System with jQuery and CSS?. 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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

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

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.

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

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.

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.

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

If we need to show documentation to the user directly in the WordPress editor, what is the best way to do it?

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

Questions about purple slash areas in Flex layouts When using Flex layouts, you may encounter some confusing phenomena, such as in the developer tools (d...
