簡體   English   中英

禁用位置:固定在距頁面底部250px時滾動

[英]Disabling position:fixed on scrolling when 250px from bottom of the page

 $(window).scroll(function() { $(".lay-fixed").css("bottom", Math.max(0, 250 - $(this).scrollBottom())); }); 
 .lay-fixed { position: fixed; right: 30px } 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div class="col-md-6 lay-fixed" id="gotobooking"> ----widget code----- </div> 

在這里,我嘗試從頁面底部250px滾動時禁用position:fixed元素。 幫助我找出解決此問題的方法。

請嘗試:

 $.fn.followTo = function (pos) { var $this = this, $window = $(window); $window.scroll(function (e) { if ($window.scrollTop() > pos) { $this.css({ position: 'absolute', top: pos }); } else { $this.css({ position: 'fixed', top: 0 }); } }); }; $('.lay-fixed').followTo(250); 
 .lay-fixed { position: fixed; right: 30px } 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div class="col-md-6 lay-fixed" id="gotobooking"> ----widget code----- </div> <div> But I must explain to you how all<br /> this mistaken idea of denouncing pleasure and praising<br /> pain was born and I will give you a complete account of the<br /> system, and expound the actual teachings of the great<br /> explorer of the truth, the master-builder of human happiness.<br /> No one rejects, dislikes, or avoids pleasure itself, because<br /> it is pleasure, but because those who do not know how<br /> to pursue pleasure rationally encounter consequences<br /> that are extremely painful. Nor again is there anyone<br /> who loves or pursues or desires to obtain pain of itself,<br /> because it is pain, but because occasionally circumstances<br /> occur in which toil and pain can procure him some great pleasure.<br /> To take a trivial example, which of us ever undertakes<br /> laborious physical exercise, except to obtain some<br /> advantage from it? But who has any right to find fault with<br /> a man who chooses to enjoy a pleasure that has no annoying<br /> consequ But I must explain to you how<br /> all this mistaken idea of denouncing pleasure and praising pain<br /> was born and I will give you a complete account of the system,<br /> and expound the actual teachings of the great explorer of<br /> the truth, the master-builder of human happiness. No one rejects,<br /> dislikes, or avoids pleasure itself, because it is pleasure,<br /> but because those who do not know how to pursue<br /> pleasure rationally encounter consequences that are<br /> extremely painful. Nor again is there anyone who loves<br /> or pursues or desires to obtain pain of itself, because it is pain,<br /> but because occasionally circumstances<br /> occur in which toil and pain can procure him some great pleasure.<br /> To take a trivial example, which of us ever undertakes<br /> laborious physical exercise, except to obtain some advantage<br /> from it? But who has any right to find fault with a man who<br /> chooses to enjoy a pleasure that has no annoying consequ<br /> But I must explain to you how all<br /> this mistaken idea of denouncing pleasure and praising pain<br /> was born and I will give you a complete account of the system,<br /> and expound the actual teachings of the great explorer of<br /> the truth, the master-builder of human happiness. No one rejects,<br /> dislikes, or avoids pleasure itself, because it is pleasure,<br /> but because those who do not know how to pursue<br /> pleasure rationally encounter consequences that are<br /> extremely painful. Nor again is there anyone who loves<br /> or pursues or desires to obtain pain of itself, because<br /> it is pain, but because occasionally circumstances occur<br /> in which toil and pain can procure him some great pleasure.<br /> To take a trivial example, which of us ever undertakes laborious<br /> physical exercise, except to obtain some advantage from it?<br /> But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequ </div> 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM