divにdivがあります。 最初のdivの高さは不明です。 2番目の高さは125pxです。スクロールでdivを翻訳する
私はこのdivに付箋のみであるスティッキーdivを作りたいと思います。
灰色のボックスはコンテナで、隣にあるソーシャルメディアのdivはスティッキーである必要があります。
コンテナより多くのコンテンツが来るので、私はposition: fixed
を使用傾ける後。私はposition: absolute
を使用して、top
の値またはtransform: translate
を変更しようとしましたが、私はその時にクロムがジッタをかいています。
私が使用しようとしたコード:
$offset = $(".social-media").offset().top;
$containerHeight = $(".sticky-container").height();
$bottom = $containerHeight + $(".sticky-container").offset().top;
$maxPoint = $containerHeight - $(".social-media").height();
$(window).scroll(function(){
if($(window).scrollTop() >= $offset){
if($(window).scrollTop() >= $bottom){
$(".social-media").css({transform: "translate(0px,"+$maxPoint+"px)"});
}else{
$scroll = $(window).scrollTop() - $offset;
$(".social-media").css({transform: "translate(0px,"+$scroll+"px)"});
}
}else{
$(".social-media").css({transform: "translate(0px,0px)"});
}
});
あなたは現在持っているもののHTMLまたはJSFiddle/Codepenの例を提供できますか? –
https://jsfiddle.net/d0fx8jcL/ここにあなたのフィドルがあります...クロムはここにジッタがありません...私のサイトではなぜそれがidkになるのですか( – Samse