简体   繁体   English

对滚动事件执行一些操作

[英]Perform some action on scroll event

I am trying to perform some action on some point when user scrolls window. 当用户滚动窗口时,我正在尝试执行某些操作。 Basically i am using some social networking button on my website when user see article of my website i am showing some tweet and like button on left side of article and when user scroll window down then my tweet and like position is fixed so its stick on there position. 基本上,我在网站上使用一些社交网络按钮,当用户看到我网站上的文章时,我在文章左侧显示一些tweet和like按钮;当用户向下滚动窗口时,我的tweet和like位置是固定的,因此它固定在那位置。

But the problem is when user scroll window down my tweet and like button collides with comment box.so how can i stop from colliding. 但是问题是当用户在我的推文上向下滚动窗口并且喜欢按钮与注释框碰撞时,那么如何才能避免碰撞。

My code is : 我的代码是:

$(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)
     }
    });
});

Please help me. 请帮我。 Thanks. 谢谢。

Use $(element).height() to determine the height of the elements (such as the "comment box"). 使用$(element).height()确定元素(例如“注释框”)的高度。 Use this value to change to position of your tools, eg: 使用此值可以更改工具的位置,例如:

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`

You could use jquery scroll() and then react accordingly. 您可以使用jquery scroll()然后做出相应的反应。 But you should provide some code so that we could help you more 但是您应该提供一些代码,以便我们可以为您提供更多帮助

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

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