1

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.

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.

Tushar Ahirrao
  • 12,669
  • 17
  • 64
  • 96
  • What do you mean with "collides"? Do they visually overlap each other? Does the JavaScript code break when the code is executed together? – Rob W Sep 19 '11 at 14:34
  • No, collide means it overlap with comment box – Tushar Ahirrao Sep 19 '11 at 14:35
  • Despite your edit, your question is still not clear to me. What exactely do you want? Changing the `position` attribute of an element? Finding a way to position the elements such that they don't overlap each other? – Rob W Sep 19 '11 at 14:40
  • @Rob, Yes am trying to find way to position the elements such that they don't overlap – Tushar Ahirrao Sep 19 '11 at 14:41

3 Answers3

2

Check this demo.

http://www.dailycoding.com/Posts/creating_always_visible_div_using_css.aspx

Pit Digger
  • 9,618
  • 23
  • 78
  • 122
2

Use $(element).height() to determine the height of the elements (such as the "comment box"). Use this value to change to position of your tools, e.g:

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`
Rob W
  • 341,306
  • 83
  • 791
  • 678
1

You could use jquery scroll() and then react accordingly. But you should provide some code so that we could help you more

Nicola Peluchetti
  • 76,206
  • 31
  • 145
  • 192