This is floating meny div xwiki-controls working when
$(window).scroll(function() {
var scrollTop = $(window).scrollTop();
or $(document).scroll(function() { var scrollTop = $(document).scrollTop();
but dont work like this
$(document).ready(function() {
var nav = $('.xwiki_controls');
var isFixed = false;
$('#parag').scroll(function() {
var scrollTop = $('#parag').scrollTop();
var shouldBeFixed = scrollTop > 250;
...
This is a sample of code which I have tested. Hope it will help you.
This is used to stick the div on top.
$(document).ready(function(){
var p = $("#stop").offset().top;
$(window).scroll(function(){
if(p<$(window).scrollTop()){
console.log("div reached");
$("#stop").css({position:"fixed",top:0});
}
else{
console.log("div out");
$("#stop").css({position:"static"});
}
})
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.