Shopify themes, liquid, logos, and UX
How can I make the add-to-cart sticky appear after a 20% or 30% scroll down? Thank in advice!
{% if template contains 'product' %} <div id="huratips-addtocart-sticky"> <form action="/cart/add" method="post"> <select name="id"> {% for variant in product.variants %} <option value="{{variant.id}}">{{variant.title}}</option> {% endfor %} </select> <input type="number" name="quantity" value="1" min="1"> <button type="submit">Add To Cart</button> </form> </div> <style> #huratips-addtocart-sticky{ display: flex; justify-content: center; position: fixed; bottom: 0; width: 100%; z-index: 9999; background: #fff; padding-top: 5px; border-top: 1px solid #e2e2e2; } #huratips-addtocart-sticky select, #huratips-addtocart-sticky input, #huratips-addtocart-sticky button{ height:40px; margin:0 5px; vertical-align: middle; } #huratips-addtocart-sticky input{ width: 60px; text-align: center; } #huratips-addtocart-sticky button{ padding:0 10px; } #huratips-addtocart-sticky button { background: green; border: none; color: white; } </style> {% endif %}
Solved! Go to the solution
This is an accepted solution.
You can try to use this code instead of.
{% if template contains 'product' %}
<script>
$(window).scroll(function(){
if ($(this).scrollTop() > 500) {
$('#huratips-addtocart-sticky').addClass('stick');
} else {
$('#huratips-addtocart-sticky').removeClass('stick');
}
});
</script>
<div id="huratips-addtocart-sticky">
<form action="/cart/add" method="post">
<select name="id">
{% for variant in product.variants %}
<option value="{{variant.id}}">{{variant.title}}</option>
{% endfor %}
</select>
<input type="number" name="quantity" value="1" min="1">
<button type="submit">Add To Cart</button>
</form>
</div>
<style>
#huratips-addtocart-sticky.stick{
display: flex;
justify-content: center;
position: fixed;
bottom: 0;
width: 100%;
z-index: 9999;
background: #fff;
padding-top: 5px;
border-top: 1px solid #e2e2e2;
}
#huratips-addtocart-sticky select,
#huratips-addtocart-sticky input,
#huratips-addtocart-sticky button{
height:40px;
margin:0 5px;
vertical-align: middle;
}
#huratips-addtocart-sticky input{
width: 60px;
text-align: center;
}
#huratips-addtocart-sticky button{
padding:0 10px;
}
#huratips-addtocart-sticky button {
background: green;
border: none;
color: white;
}
</style>
{% endif %}
If it is not working, please add this addition code above <script> tag
<script src="https://code.jquery.com/jquery-1.12.4.min.js" integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ=" crossorigin="anonymous"></script>
- Helpful? Like and Accept solution! Or Support me: Buy Coffees
- Reton: Loyalty & Rewards - Earn points through tasks, redeem for discounts, and enjoy exclusive VIP rewards!
- Ryviu - Reviews & QA app: Collect product reviews, import reviews from AliExpress, Amazon, Etsy, Walmart, Shopee, Dhgate and CSV.
- Lookfy Gallery: Lookbook Image: Easy and fast to create Photo Gallery, Lookbook, Shop The Look.
- Reelfy‑Shoppable Videos+Reels: Create shoppable videos to engage customers and drive more sales.
- Enjoy 1 month of Shopify for $1. Sign up now.
This is an accepted solution.
You can try to use this code instead of.
{% if template contains 'product' %}
<script>
$(window).scroll(function(){
if ($(this).scrollTop() > 500) {
$('#huratips-addtocart-sticky').addClass('stick');
} else {
$('#huratips-addtocart-sticky').removeClass('stick');
}
});
</script>
<div id="huratips-addtocart-sticky">
<form action="/cart/add" method="post">
<select name="id">
{% for variant in product.variants %}
<option value="{{variant.id}}">{{variant.title}}</option>
{% endfor %}
</select>
<input type="number" name="quantity" value="1" min="1">
<button type="submit">Add To Cart</button>
</form>
</div>
<style>
#huratips-addtocart-sticky.stick{
display: flex;
justify-content: center;
position: fixed;
bottom: 0;
width: 100%;
z-index: 9999;
background: #fff;
padding-top: 5px;
border-top: 1px solid #e2e2e2;
}
#huratips-addtocart-sticky select,
#huratips-addtocart-sticky input,
#huratips-addtocart-sticky button{
height:40px;
margin:0 5px;
vertical-align: middle;
}
#huratips-addtocart-sticky input{
width: 60px;
text-align: center;
}
#huratips-addtocart-sticky button{
padding:0 10px;
}
#huratips-addtocart-sticky button {
background: green;
border: none;
color: white;
}
</style>
{% endif %}
If it is not working, please add this addition code above <script> tag
<script src="https://code.jquery.com/jquery-1.12.4.min.js" integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ=" crossorigin="anonymous"></script>
- Helpful? Like and Accept solution! Or Support me: Buy Coffees
- Reton: Loyalty & Rewards - Earn points through tasks, redeem for discounts, and enjoy exclusive VIP rewards!
- Ryviu - Reviews & QA app: Collect product reviews, import reviews from AliExpress, Amazon, Etsy, Walmart, Shopee, Dhgate and CSV.
- Lookfy Gallery: Lookbook Image: Easy and fast to create Photo Gallery, Lookbook, Shop The Look.
- Reelfy‑Shoppable Videos+Reels: Create shoppable videos to engage customers and drive more sales.
- Enjoy 1 month of Shopify for $1. Sign up now.
It's working perfectly! Thank you!
Hey Community! As the holiday season unfolds, we want to extend heartfelt thanks to a...
By JasonH Dec 6, 2024Dropshipping, a high-growth, $226 billion-dollar industry, remains a highly dynamic bus...
By JasonH Nov 27, 2024Hey Community! It’s time to share some appreciation and celebrate what we have accomplis...
By JasonH Nov 14, 2024