How to enable parallax on mobile? (Currently functional on desktop)

How to enable parallax on mobile? (Currently functional on desktop)

empiricalarby
Trailblazer
230 1 53

https://empiricalwater.com/

 

On desktop, you'll see a parallax effect on the banner image. It works beautifully.

 

However on mobile, it is quite zoomed in, and no parallax effect is applied.

 

Here's the code:

Desktop Screenshot 2023.11.22 - 13.51.07.65.png

 

Please advise, thanks!

Replies 7 (7)

BSS-Commerce
Shopify Partner
3477 464 552

Hello @empiricalarby ,

I checked your website and they work fine on Android devices. The fact that they do not work on IOS devices, is because IOS has some properties that require the "-webkit-" prefix. You can try changing and checking again. The reason why the image on the banner is zoomed is because your background-size attribute is for cover. You can convert it to contain but that will give the banner more space. I don't think it's a concern that the photos are zoomed in because they still look great. Here is the image I saw on your website for Android device:

view - 2023-11-23T103937.673.png

If our suggestions are useful, please let us know by giving it a like, marking it as a solution, or donating here .


B2B Solution & Custom Pricing | Product Labels by BSS


Need help from our expert? Kindly share your request with us via community@bsscommerce.com


BSS Commerce - Full-service eCommerce Agency
empiricalarby
Trailblazer
230 1 53

IMG_9831.png

Unfortunately on iOS, it's so far zoomed in it's impossible to tell what the image is. Any idea how to solve this? Thanks

BSS-Commerce
Shopify Partner
3477 464 552

Hey @empiricalarby 

 

I tried to find a solution to your problem. The result is that the banner part does not work as expected because background-attachment: fixed;. Since iOS 7, Apple has disabled this attribute due to the high cost. So I give you 2 solutions as follows:

- First method: do not apply background-attackment to iOS devices. Please change your code style to

 

#shopify-section-template--16982408331515__4938a73e-1164-49e8-bf7e-9c9ef4ff4938 .banner__media {
    background-image: url(https://empiricalwater.com/cdn/shop/files/New_b9891b18-5626-46fa-833a-46437fa9fbe1.jpg?v=1700516265&width=2500);
    background-size: cover;
    background-repeat: no-repeat;
    background-position: center;
    min-height: 400px;
}

Then add the following code to the theme.liquid section:

<script>
function iOS() {
  return [
    'iPad Simulator',
    'iPhone Simulator',
    'iPod Simulator',
    'iPad',
    'iPhone',
    'iPod'
  ].includes(navigator.platform)
  // iPad on iOS 13 detection
  || (navigator.userAgent.includes("Mac") && "ontouchend" in document)
}
let isIOS = iOS();
if (!isIOS) {
 document.querySelector("#shopify-section-template--16982408331515__4938a73e-1164-49e8-bf7e-9c9ef4ff4938 .banner__media").style.backgroundAttachment = "fixed"
}
</script>

- Or you can redo another banner without using the background-attachment attribute
Here are the results:

view - 2023-11-23T161839.324.png and parallax effect still works normally on desktop as well as android devices.

If our suggestions are useful, please let us know by giving it a like, marking it as a solution, or donating here .


B2B Solution & Custom Pricing | Product Labels by BSS


Need help from our expert? Kindly share your request with us via community@bsscommerce.com


BSS Commerce - Full-service eCommerce Agency
empiricalarby
Trailblazer
230 1 53

I am having trouble following the first method.

Desktop Screenshot 2023.11.23 - 12.19.23.09.png

What did I do wrong here? Thanks

BSS-Commerce
Shopify Partner
3477 464 552

Hey @empiricalarby ,

 

Sorry for this inconvenience. It seems we didn't understand each other. So I'll show you the details:

Please delete all the code in the blue paragraph below:

view - 2023-11-24T093846.415.png

Then paste the following code there:

<style>
#shopify-section-template--16982408331515__4938a73e-1164-49e8-bf7e-9c9ef4ff4938 .banner__media {
    background-image: url(https://empiricalwater.com/cdn/shop/files/New_b9891b18-5626-46fa-833a-46437fa9fbe1.jpg?v=1700516265&width=2500);
    background-size: cover;
    background-repeat: no-repeat;
    background-position: center;
    min-height: 400px;
}

#shopify-section-template--16982408331515__4938a73e-1164-49e8-bf7e-9c9ef4ff4938 .banner__media img {
opacity:0;
}
</style>

<script>
function iOS() {
  return [
    'iPad Simulator',
    'iPhone Simulator',
    'iPod Simulator',
    'iPad',
    'iPhone',
    'iPod'
  ].includes(navigator.platform)
  // iPad on iOS 13 detection
  || (navigator.userAgent.includes("Mac") && "ontouchend" in document)
}
let isIOS = iOS();
if (!isIOS) {
 document.querySelector("#shopify-section-template--16982408331515__4938a73e-1164-49e8-bf7e-9c9ef4ff4938 .banner__media").style.backgroundAttachment = "fixed"
}
</script>

 

If our suggestions are useful, please let us know by giving it a like, marking it as a solution, or donating here .


B2B Solution & Custom Pricing | Product Labels by BSS


Need help from our expert? Kindly share your request with us via community@bsscommerce.com


BSS Commerce - Full-service eCommerce Agency
empiricalarby
Trailblazer
230 1 53

Hi there, sorry to bother again. Can you check that I've done it correctly?

Desktop Screenshot 2023.11.23 - 20.02.36.49.png

I'm not seeing any kind of parallax effect yet. All I notice is a slightly different placement of the image. Thank you

silkybts
New Member
4 0 0

Hello! 

 

I'm having a similar issue where my parallax effect is applied to the entire background of my site. 

It looks fine on the computer and mobile previews on Shopify, but on my iPhone it is a scrolling (i.e. non-parallax), very zoomed in version. 

 

Side note; on my home page there are spaces between my sections where the parallax effect has not been applied to (looks like solid blocks moving over my background) - might you know how to remove these? 

 

My website URL is www.silkyloungewear.com

 

Thanks for all your help!

Lydia