Creating HTML that adjusts to the size of the viewport

After completing my first webpage, I implemented a parallax/split scroll effect using ScrollMagic.js.

However, when testing the page in mobile view using Chrome's developer tools, I noticed that the parallax effect was not working properly due to misaligned triggers.

In search of a solution, I stumbled upon a helpful thread on Stack Overflow discussing Parallax scrolling not working on mobile css. The consensus was that parallaxes often struggle on mobile devices, and it is advised to disable the effect once a certain viewport size is reached.

You can see an example of this issue in action on my CodePen here: https://codepen.io/Jaderianne/pen/jjgWpv. As you resize the browser window, you'll notice that the text in the parallax section becomes cramped, indicating the need to disable the effect on smaller screens.

Being new to web development and still learning, I am unsure of how to implement the necessary changes to disable the parallax on smaller screens. I believe I will need to use CSS @media queries, but I'm uncertain about the specifics.

If anyone could offer guidance or assistance, I would greatly appreciate it. You can find the code snippet on my linked CodePen for reference.

Here is a snippet from the HTML:

<section id="About" class="about">

<div class="about-title">
  <h2>About Us</h2>
</div>

<div class="about-pages">
  <div>
    <h2>About 1</h2>
    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Animi, 
soluta ipsam, minima delectus eaque omnis!</p>
  </div>
  <div>
    <h2>About 2</h2>
    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Animi, 
soluta ipsam, minima delectus eaque omnis!</p>
  </div>
  <div>
    <h2>About 3</h2>
   <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Animi, 
soluta ipsam, minima delectus eaque omnis!</p>
  </div>
</div>
</section>

The corresponding CSS and Javascript can be viewed on the provided CodePen link.

Javascript:

function splitScroll() {
const controller = new ScrollMagic.Controller();

new ScrollMagic.Scene({
  duration: '200%',
  triggerElement: '.about-title',
  triggerHook: 0
})

.setPin('.about-title')
.addTo(controller)

new ScrollMagic.Scene({
    duration: '200%',
    triggerElement: '.services-title',
    triggerHook: 0
  })

  .setPin('.services-title')
  .addTo(controller)

}

splitScroll();

I aim to have the "About 1," "About 2," and "About 3" sections appear directly beneath the "About Us" section (and vice versa for the Services section) when viewed on a mobile device.

Answer №1

There may be another approach to consider for optimizing your website for mobile devices. One option is to create a separate div specifically designed for mobile, while hiding it using 'display: none.' Within this new div, you can include all the necessary styling for the non-parallax mobile view. To control when this mobile-specific styling appears, you can utilize '@media screen and (max-width: 500px) {' in your CSS code. This will ensure that the mobile layout is only displayed when the screen size is below 500px (typical of phone width).

Answer №2

If you want to disable the parallax effect, consider disabling your controller. Additionally, parallax will not function on viewport widths less than 800px (you can adjust these variables in both CSS and JS).

To disable the controller, simply run the following command:

controller.destroy()

Check out the codepen example here: https://codepen.io/anon/pen/XLvaEQ

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

Semantic UI dropdown field not displaying selected option text

I've encountered an issue while working with React Semantic UI. I'm trying to render a dropdown and have configured it so that the selected option's text should display in the field. However, when I choose an option from the dropdown, instea ...

1 out of the 3 Submit buttons in the form is malfunctioning and not working properly

Scenario : There is a Bootstrap 4 form with: 1 submit button at the bottom. 2 modals, each with a submit button. Working Submit buttons : The main submit button is functional. The submit button for Add new contractor modal is also working. ...

How can the presence of a CSS rule prevent another from being applied?

My attempt to create this HTML file in Chrome posed some challenges: <style> br { }​ [required] { border-width: 3px; border-color: red; } </style> <input required /> The entire content of the file is shown above. However, I noti ...

Adjust font size proportions in CSS3

I am currently experimenting with the new font-face feature in CSS3 to use custom TTF/OTF fonts. My question is: can I adjust the default font size ratio? For example, if I am using Tahoma with a default 9pt font size and want to switch to my own custom ...

Minimize the gaps between items within a CSS grid design

I'm struggling with adjusting the whitespace between 'Job Role' and 'Company Name' in my grid layout. Here's a snippet of what I have: https://i.sstatic.net/l55oW.png The container css is set up like this: .experience-child ...

The Fullpage.js embedded in an iframe is experiencing difficulty scrolling on iOS mobile devices

Trying to use Fullpage.js for a website with unique sections on different domains using full-screen iframes. However, encountering issues with scrolling on IOS mobile devices. The first solution rendered the page completely unscrollable: <iframe src=" ...

Having trouble scrolling on iPad screen after closing a pop-up window

Homepage featuring buttons and scrollable content, click on one of the buttons on the right-hand side. Full-page or half-page cover popup appears. After closing the popup, attempting to scroll the page results in the content being hidden behind a white scr ...

The issue with setting width using % in React Native is causing trouble

While working on my project using expo react native, I encountered an issue with a horizontal scrollview for images. When I style the images using pixels like this: <Image code... style={{width: 350}}/>, everything works fine. However, if I try to ch ...

Use jQuery's AJAX function to upload an array

Having a bit of trouble with a seemingly simple task. I need to send a multi-dimensional array to a php page using jQuery's .ajax function, but I'm struggling to serialize the array correctly. This is the code snippet: var dataToSend = new Arra ...

Styling PHP echo in HTML

This seems like it should be simple, but there's clearly something I'm missing here. If anyone can point me in the right direction and give me a hint, I would truly appreciate it! Thank you and have an amazing day! <?php $code = '1 ...

Is there a way to ensure that the border of a textarea matches the border of a text input?

My goal is to make the textarea fields in my form have the same appearance as the text input fields, regardless of the browser being used. I am interested in achieving this without imposing a customized style, but instead by leveraging the standard style w ...

Ways to reposition JavaScript output within a webpage

I am new to HTML, CSS, and JavaScript and I have a question regarding how they work together. I can use JavaScript to display objects on the page, but I'm unsure how to move them around like other elements. Is CSS the solution for this? Any advice w ...

Ensure the CSS class stays on Quill clipboard.dangerouslyPasteHTML

One of the challenges I face with using the Quill Text Editor is that when I use the method clipboard.dangerouslyPasteHTML to paste HTML into the editor, it does not maintain custom CSS classes. For example: let content= '<p class="perso-clas ...

Mastering JavaScript Loops

Looking to create an endless loop of links that never stop? I need assistance achieving this. setTimeout(linkToGoogle, 5000); function linkToGoogle() { document.getElementById('myAnchor').innerHTML="Visit Google"; document.getElementById(&a ...

Enhancing functionality with extra JavaScript tags in next.js

Recently, I delved into programming with react & next.js after previously working with node.js. It didn't take long for me to create my first application, but upon inspecting the page, I noticed an abundance of extra JavaScript code (see image below). ...

Centralize and confine the menu division

I have been working on creating a hover menu using CSS and Bootstrap, specifically for flex grid layouts. However, I have run into an issue where my menu is only as wide as its parent div. Furthermore, I am struggling to center the hover menu relative to ...

AngularJS Dropdown in ASP.NET MVC 3

I want to create a DropDownList using @Html.DropDownList and connect it with AngularJS. Below is the code snippet: @Html.DropDownList("LessonID", (SelectList)ViewBag.LessonList, "choose one", new { ng_model = "LessonID" }) Here's an example of ...

How to transform text into an image using jQuery

After using Yii2 framework to generate my code, I encountered an issue where the text inside labels represents image URLs. My attempt to convert this text into images using jQuery and appending them was unsuccessful. Here is the code generated by Yii2: &l ...

jQuery-powered automatic horizontal scrolling

Does anyone know of a jQuery plugin that allows for scrolling of a div element when hovering over an arrow? The desired functionality is similar to the following image: , where the content inside automatically scrolls left or right when the user hovers ove ...

Is there a way to simulate a virtual keyboard event (specifically the tab key) using Javascript in Internet Explorer 8

I'm looking to create a virtual keyboard event for tab using JavaScript. I've researched this topic and found some helpful answers, but I haven't been able to get it working properly. I know that JavaScript is an event-driven language and ty ...