[英]Perform some action on scroll event
当用户滚动窗口时,我正在尝试执行某些操作。 基本上,我在网站上使用一些社交网络按钮,当用户看到我网站上的文章时,我在文章左侧显示一些tweet和like按钮;当用户向下滚动窗口时,我的tweet和like位置是固定的,因此它固定在那位置。
但是问题是当用户在我的推文上向下滚动窗口并且喜欢按钮与注释框碰撞时,那么如何才能避免碰撞。
我的代码是:
$(document).ready(function(){
alert($(".comment-content").offset().top);
$(window).scroll(function () {
if($(window).scrollTop()=="1260"){
// want to change position of tweet and like button to relative; ( position:relative)
}
});
});
请帮我。 谢谢。
使用$(element).height()
确定元素(例如“注释框”)的高度。 使用此值可以更改工具的位置,例如:
var offset = $("#comments-box").height();
var mytoolbox = $("#myToolbox");
offset = offset+20; // Function logic (example). Adjust this line to meet your wishes
mytoolbox.css("bottom", offset+"px"); //In conjunction with `position:fixed`
mytoolbox.css("top", offset+"px"); //When used in conjunction with `position:absolute`
您可以使用jquery scroll()然后做出相应的反应。 但是您应该提供一些代码,以便我们可以为您提供更多帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.