简体   繁体   English

使用 jquery 制作粘性 div

[英]Making a sticky div using jquery

I am currently working on a shopify store and trying to make a sticky div using jquery but unable to do that.我目前正在一家 shopify 商店工作,并尝试使用 jquery 制作一个粘性 div,但无法做到这一点。 Here is my code please have a look if Iam doing right??这是我的代码,请看看我做得对吗??

 <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> <script src="assets/jquery.sticky.js"></script> <script> $(document).ready(function(){ $("#fixed").sticky({topSpacing:50}); }); </script>
 <div class="main" style="width:100%;, position:absolute;"> <div class="fixed" id="fixed" style="height: 80px; "> <button class="cart-btn"> IN DEN WARENKORB LEGEN</button> </div> </div>

You have a typo in this line:你在这一行有一个错字:

<div class="main" style="width:100%;, position:absolute;">
                                   ^^^

Remove the comma and it works:删除逗号,它的工作原理:

 $("#fixed").sticky({topSpacing: 50});
 .main { background: #bada55; color: white; font-family: Droid Sans; font-size: 18px; line-height: 1.6em; font-weight: bold; text-align: center; padding: 10px; text-shadow: 0 1px 1px rgba(0,0,0,.2); box-sizing:border-box; }
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://cdn.jsdelivr.net/gh/garand/sticky@master/jquery.sticky.js"></script> <div class="main" style="width:100%; position:absolute;"> <div class="fixed" id="fixed" style="height: 80px; "> <button class="cart-btn"> IN DEN WARENKORB LEGEN</button> </div> </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM