How to do this it's very simple here example see below .
Demo Jsfiddle
Jquery Code
var oritop = -100;
$(window).scroll(function() {
var scrollt = $(this).scrollTop();
var elm = $(".scrollTopWindow");
if(oritop < 0) {
oritop= elm.offset().top;
}
if(scrollt >= oritop) {
elm.css({"position": "fixed", "top": 0, "left": 0});
}
else {
elm.css("position", "static");
}
});
Css here code as Sample
body{height:2000px}
.scrollTopWindow {
background-color: red;
width: 150px;
height: 100px;
color: white;
padding:20px;
}
HTML Code here
Some Content here
Some Content here
Some Content here
Some Content here
Some Content here
Some Content here
Some Content here
Some Content here
Some Content here
Some Content here
Some Content here
Some Content here
Some Content here
Some Content here
Some Content here
<div class = "scrollTopWindow"> Scroll top window and fix me ! </div>
Demo Jsfiddle
0 comments:
Post a Comment