Reducing Collections banner height while scrolling, Spotlight Theme

Solved

Reducing Collections banner height while scrolling, Spotlight Theme

starscream911
Explorer
52 0 14

Hello experts! 

 

I want my collection banner to reduce it's height while scrolling on mobile and desktop. 
Please suggest me code to execute. See photos, the black section is our target.

0-02-05-65fcd22dba9508c7106b2db42977943a3326f39f1a20a3ae60c9be2c9dec0f84_9c68b5bcaeb6b492.jpg0-02-05-c73d99b2157420099967a3ba133028c379ca34110375e03f638ac8858dc7750c_766bd97ab8080eb5.jpg  

Accepted Solution (1)
Dan-From-Ryviu
Shopify Partner
11633 2280 2462

This is an accepted solution.

Update the code and check again

<script>
  window.addEventListener('scroll', function() {
    var banner = document.getElementById('shopify-section-template--23131122794838__banner');
    var threshold = 50; // Change this value to adjust when the class is added

    if (window.scrollY > threshold) {
      // Add the class when scrolled down beyond the threshold
      banner.classList.add('reduce-section');
    } else {
      // Remove the class if scrolled back above the threshold
      banner.classList.remove('reduce-section');
    }
  });
</script>
<style>
#shopify-section-template--23131122794838__banner.reduce-section .collection-hero__title { 
    margin: 1.2rem 0;
    font-size: 20px !important;
}
</style>

 

- Helpful? Like & Accept solution!
- Ryviu - Product Reviews & QA app: Collect customer reviews, import reviews from AliExpress, Amazon, Etsy, Walmart, Dhgate and CSV.
- Reton: Loyalty & Rewards - Earn points through tasks, redeem for discounts, and enjoy exclusive VIP rewards!
- Lookfy Gallery: Lookbook Image - Gain customers with photo gallery, video & shoppable image
- Reelfy‑Shoppable Videos+Reels: Create shoppable videos to engage customers and drive more sales.
- En...
Sign up now.

View solution in original post

Replies 22 (22)

rajweb
Shopify Partner
795 69 147

Hey @starscream911 ,

Could you share your store URL so I can check?

Rajat | Shopify Expert Developer
Need a reliable Shopify developer for your next project?
Our App: Productify Groups App
Email: rajat.shopify@gmail.com
Portfolio: https://rajatweb.dev
starscream911
Explorer
52 0 14
rajweb
Shopify Partner
795 69 147

Hey @starscream911 ,

To reduce the height of the collection banner while scrolling on both mobile and desktop, you can use a combination of CSS and JavaScript (or jQuery) to achieve this effect. Below is an example of how you might implement this.

CSS:

First, add the following CSS to your theme's stylesheet to define the initial and scrolled states of your banner:

/* Initial state for the collection banner */
.collection-banner {
    height: 300px; /* Adjust the initial height as needed */
    transition: height 0.3s ease; /* Smooth transition effect */
}

/* Scrolled state for the collection banner */
.collection-banner.scrolled {
    height: 100px; /* Adjust the reduced height as needed */
}

Javascript&colon;

Next, add this JavaScript code to your theme. You can place it in your theme's JavaScript file or within the <script> tags in the theme.liquid file.

document.addEventListener('scroll', function() {
    const banner = document.querySelector('.collection-banner');
    if (banner) {
        if (window.scrollY > 50) { // Adjust this value to change when the height reduces
            banner.classList.add('scrolled');
        } else {
            banner.classList.remove('scrolled');
        }
    }
});

Instructions:

1. Go to Online Store > Themes > Edit Code.  In the Assets  folder, find your stylesheet (usually  theme.css or style.css) and add the CSS code at the bottom.

2. Add the  Javascript&colon;  In the same Edit Code section, find the Assets folder again and locate your JavaScript file (often named theme.js or similar). Paste the JavaScript code at the bottom of the file.

3. Adjust Values : You may need to adjust the height values and the scroll threshold in the JavaScript code according to your design preferences.

4.  After adding the code, make sure to save the changes.

After implementing the code, test it on both mobile and desktop devices to ensure the height reduction works as expected when you scroll down the page. Let me know if you need any further adjustments or assistance!

thanks

Rajat | Shopify Expert Developer
Need a reliable Shopify developer for your next project?
Our App: Productify Groups App
Email: rajat.shopify@gmail.com
Portfolio: https://rajatweb.dev

GTLOfficial
Shopify Partner
834 171 188

Hello @starscream911 
Go to online store ----> themes ----> actions ----> edit code ---->base.css
add this code at the end of the file and save.

@media screen and (min-width: 749px) {
.header.header--middle-center.header--mobile-center.page-width.header--has-menu.header--has-social {
height: 11rem !important;
margin-top: -5rem !important;
}
}
@media screen and (max-width: 749px) {
.header.header--middle-center.header--mobile-center.page-width.header--has-menu.header--has-social {
height: 7rem !important;
margin-top: -3rem !important;
}
}

result
8.png7.png

If this was helpful, hit the like button and accept the solution.
Thanks

- Buy me a Pizza
- If helpful then please Like and Accept Solution.
- Want to modify or custom changes or bug fix on the store Hire me. GTL web solutions
- Want Complete Storefront: Send an email ⇨- Email: info@gtlofficial.com - Skype: ritesh_27dh
starscream911
Explorer
52 0 14

Hello! 

This is out of point, and this code doesn't work at all.

Dan-From-Ryviu
Shopify Partner
11633 2280 2462

Hi, please try to add this addition code in theme.liquid file and check

<script>
  window.addEventListener('scroll', function() {
    var banner = document.getElementById('shopify-section-template--23131122794838__banner');
    
    if (window.scrollY === 0) {
      // Add the class when scrolled to the top
      banner.classList.add('reduce-section');
    } else {
      // Remove the class if scrolled away from the top
      banner.classList.remove('reduce-section');
    }
  });
</script>
<style>
#shopify-section-template--23131122794838__banner.reduce-section .collection-hero__title { 
    margin: 1.5rem 0;
}
</style>

 

- Helpful? Like & Accept solution!
- Ryviu - Product Reviews & QA app: Collect customer reviews, import reviews from AliExpress, Amazon, Etsy, Walmart, Dhgate and CSV.
- Reton: Loyalty & Rewards - Earn points through tasks, redeem for discounts, and enjoy exclusive VIP rewards!
- Lookfy Gallery: Lookbook Image - Gain customers with photo gallery, video & shoppable image
- Reelfy‑Shoppable Videos+Reels: Create shoppable videos to engage customers and drive more sales.
- En...
Sign up now.

starscream911
Explorer
52 0 14

where exactly to add this?

Dan-From-Ryviu
Shopify Partner
11633 2280 2462

theme.liquid file, before </head> 

 

- Helpful? Like & Accept solution!
- Ryviu - Product Reviews & QA app: Collect customer reviews, import reviews from AliExpress, Amazon, Etsy, Walmart, Dhgate and CSV.
- Reton: Loyalty & Rewards - Earn points through tasks, redeem for discounts, and enjoy exclusive VIP rewards!
- Lookfy Gallery: Lookbook Image - Gain customers with photo gallery, video & shoppable image
- Reelfy‑Shoppable Videos+Reels: Create shoppable videos to engage customers and drive more sales.
- En...
Sign up now.

starscream911
Explorer
52 0 14

Doesn't work as we expect. Resizing takes too much time and it actually happens when i scroll down and go back to the top - then we see this section reduced, but not when scrolling down at first place. And also can we do more reducing when we choose "Relationships & Parenting" collection?

starscream911
Explorer
52 0 14

This doesn't work properly. It reduces the size but after a period of time, I want it immediately auto reducing. 

Dan-From-Ryviu
Shopify Partner
11633 2280 2462

So please update the code to this 

<script>
  window.addEventListener('scroll', function() {
    var banner = document.getElementById('shopify-section-template--23131122794838__banner');
    var threshold = 50; // Change this value to adjust when the class is added

    if (window.scrollY > threshold) {
      // Add the class when scrolled down beyond the threshold
      banner.classList.add('reduce-section');
    } else {
      // Remove the class if scrolled back above the threshold
      banner.classList.remove('reduce-section');
    }
  });
</script>
<style>
#shopify-section-template--23131122794838__banner.reduce-section .collection-hero__title { 
    margin: 1.5rem 0;
}
</style>

- Helpful? Like & Accept solution!
- Ryviu - Product Reviews & QA app: Collect customer reviews, import reviews from AliExpress, Amazon, Etsy, Walmart, Dhgate and CSV.
- Reton: Loyalty & Rewards - Earn points through tasks, redeem for discounts, and enjoy exclusive VIP rewards!
- Lookfy Gallery: Lookbook Image - Gain customers with photo gallery, video & shoppable image
- Reelfy‑Shoppable Videos+Reels: Create shoppable videos to engage customers and drive more sales.
- En...
Sign up now.

starscream911
Explorer
52 0 14

It works perfectly now! Also can we reduce the banner height a bit more when it is already reduced, in mobile preview. "Relationships & Parenting" niche is on 2 rows for more aestethic view, can the banner be with less height in general?

Dan-From-Ryviu
Shopify Partner
11633 2280 2462

This is an accepted solution.

Update the code and check again

<script>
  window.addEventListener('scroll', function() {
    var banner = document.getElementById('shopify-section-template--23131122794838__banner');
    var threshold = 50; // Change this value to adjust when the class is added

    if (window.scrollY > threshold) {
      // Add the class when scrolled down beyond the threshold
      banner.classList.add('reduce-section');
    } else {
      // Remove the class if scrolled back above the threshold
      banner.classList.remove('reduce-section');
    }
  });
</script>
<style>
#shopify-section-template--23131122794838__banner.reduce-section .collection-hero__title { 
    margin: 1.2rem 0;
    font-size: 20px !important;
}
</style>

 

- Helpful? Like & Accept solution!
- Ryviu - Product Reviews & QA app: Collect customer reviews, import reviews from AliExpress, Amazon, Etsy, Walmart, Dhgate and CSV.
- Reton: Loyalty & Rewards - Earn points through tasks, redeem for discounts, and enjoy exclusive VIP rewards!
- Lookfy Gallery: Lookbook Image - Gain customers with photo gallery, video & shoppable image
- Reelfy‑Shoppable Videos+Reels: Create shoppable videos to engage customers and drive more sales.
- En...
Sign up now.

starscream911
Explorer
52 0 14

PerfecT! Now please let's make it with same padding on the top and the bottom, because in the moment the text itself is a bit lifted to the top?

starscream911
Explorer
52 0 14

PerfecT! Now please let's make it with same padding on the top and the bottom, because in the moment the text itself is a bit lifted to the top?

starscream911
Explorer
52 0 14

Can you please response to my final question???

Dan-From-Ryviu
Shopify Partner
11633 2280 2462

Please update code to this and check again 

<script>
  window.addEventListener('scroll', function() {
    var banner = document.getElementById('shopify-section-template--23131122794838__banner');
    var threshold = 50; // Change this value to adjust when the class is added

    if (window.scrollY > threshold) {
      // Add the class when scrolled down beyond the threshold
      banner.classList.add('reduce-section');
    } else {
      // Remove the class if scrolled back above the threshold
      banner.classList.remove('reduce-section');
    }
  });
</script>
<style>
#shopify-section-template--23131122794838__banner.reduce-section .collection-hero__title { 
    margin: 1.2rem 0;
    font-size: 20px !important;
    line-height: 1;
}
</style>

- Helpful? Like & Accept solution!
- Ryviu - Product Reviews & QA app: Collect customer reviews, import reviews from AliExpress, Amazon, Etsy, Walmart, Dhgate and CSV.
- Reton: Loyalty & Rewards - Earn points through tasks, redeem for discounts, and enjoy exclusive VIP rewards!
- Lookfy Gallery: Lookbook Image - Gain customers with photo gallery, video & shoppable image
- Reelfy‑Shoppable Videos+Reels: Create shoppable videos to engage customers and drive more sales.
- En...
Sign up now.

starscream911
Explorer
52 0 14

maybe it still needs adjustment 0-02-05-2ee2e5aba9a168ae3c28bb95749e0d395faaaa39b4fbd5938dbf1b0678a7fad8_b035f53853d9f333.jpg

Dan-From-Ryviu
Shopify Partner
11633 2280 2462

Try to update coded and check again

<script>
  window.addEventListener('scroll', function() {
    var banner = document.getElementById('shopify-section-template--23131122794838__banner');
    var threshold = 50; // Change this value to adjust when the class is added

    if (window.scrollY > threshold) {
      // Add the class when scrolled down beyond the threshold
      banner.classList.add('reduce-section');
    } else {
      // Remove the class if scrolled back above the threshold
      banner.classList.remove('reduce-section');
    }
  });
</script>
<style>
#shopify-section-template--23131122794838__banner.reduce-section .collection-hero__title { 
    margin: 1.2rem 0;
    font-size: 20px !important;
    line-height: 1;
    display: flex;
    align-items: center;
}
</style>

- Helpful? Like & Accept solution!
- Ryviu - Product Reviews & QA app: Collect customer reviews, import reviews from AliExpress, Amazon, Etsy, Walmart, Dhgate and CSV.
- Reton: Loyalty & Rewards - Earn points through tasks, redeem for discounts, and enjoy exclusive VIP rewards!
- Lookfy Gallery: Lookbook Image - Gain customers with photo gallery, video & shoppable image
- Reelfy‑Shoppable Videos+Reels: Create shoppable videos to engage customers and drive more sales.
- En...
Sign up now.

starscream911
Explorer
52 0 14

no this doesn't work, we are talking about vertical adjustment. Vertical center. 

0-02-05-2ee2e5aba9a168ae3c28bb95749e0d395faaaa39b4fbd5938dbf1b0678a7fad8_b035f53853d9f333.jpg


Also please note i have custom css for the h1 , if you think tell me to delete it, and also give me working code for the vertical adjust of it.

clipboard_image_246f9f93927d96.jpg

starscream911
Explorer
52 0 14

Can you please center the text between bottom and top???

Dan-From-Ryviu
Shopify Partner
11633 2280 2462

Code update 

<script>
  window.addEventListener('scroll', function() {
    var banner = document.getElementById('shopify-section-template--23131122794838__banner');
    var threshold = 50; // Change this value to adjust when the class is added

    if (window.scrollY > threshold) {
      // Add the class when scrolled down beyond the threshold
      banner.classList.add('reduce-section');
    } else {
      // Remove the class if scrolled back above the threshold
      banner.classList.remove('reduce-section');
    }
  });
</script>
<style>
@media (max-width: 749px) {
#shopify-section-template--23131122794838__banner { top: 44px !important; }
}
#shopify-section-template--23131122794838__banner.reduce-section .collection-hero__title { 
    margin: 1.2rem 0;
    font-size: 20px !important;
    line-height: 1;
    display: flex;
    align-items: center;
}
</style>

- Helpful? Like & Accept solution!
- Ryviu - Product Reviews & QA app: Collect customer reviews, import reviews from AliExpress, Amazon, Etsy, Walmart, Dhgate and CSV.
- Reton: Loyalty & Rewards - Earn points through tasks, redeem for discounts, and enjoy exclusive VIP rewards!
- Lookfy Gallery: Lookbook Image - Gain customers with photo gallery, video & shoppable image
- Reelfy‑Shoppable Videos+Reels: Create shoppable videos to engage customers and drive more sales.
- En...
Sign up now.