


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!

Here's a container with some child elements:

Flyout menus! The second you need to implement a menu that uses a hover event to display more menu items, you're in tricky territory. For one, they should

"The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect."- Tim Berners-Lee

In this week's roundup: datepickers are giving keyboard users headaches, a new web component compiler that helps fight FOUC, we finally get our hands on styling list item markers, and four steps to getting webmentions on your site.

The short answer: flex-shrink and flex-basis are probably what you’re lookin’ for.

In this week's look around the world of web platform news, Google Search Console makes it easier to view crawled markup, we learn that custom properties

The IndieWeb is a thing! They've got a conference coming up and everything. The New Yorker is even writing about it:


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

Dreamweaver CS6
Visual web development tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Chinese version
Chinese version, very easy to use

Atom editor mac version download
The most popular open source editor