ページ上部に固定する位置を設定しました。これは、ドキュメントやページの中央にスクロールしながら、これを私の後にします。ドキュメントの途中でドキュメントの途中でこれを貼り付け、それを使わずにスカルダウンしたいと思います。私が再び上にスクロールした後、私はそれを私に追いつけたい(固定位置)。ここでスクロール後のJavaScriptの固定位置を一定距離外す
は、私が働いているコードのスニペットです。
if ($('body').hasClass('catalog-product-view')) {
if ($(this).scrollTop() >= $('.product-collateral-wrapper').innerHeight()/2)
{
my div should remain in its place now. waiting for me to scoll up again to follow me
}else{
have my div fixed positioned so when I scroll the page, I always see it.
}
Here is the full function
$(window).scroll(function() {
if ($(this).scrollTop() > offset && !stickyActive) {
stickyActive = true;
$header.addClass("sticky-active");
$(stickyPlaceholder).show();
var logo = $('<li></li>').append($('.main-header .logo-container > a').clone()).html();
logo = '<li class="logo-fixed">'+logo+'</li>';
$('.main-header nav.top-bar.main-nav .top-bar-section .left').prepend(logo);
if ($('.top-bar-section .main-logo-sticky').length) {
$('.top-bar-section .main-logo').hide();
}
topbarLeftHeight = $('.main-header nav.top-bar.main-nav .top-bar-section .left').outerHeight();
} else if ($(this).scrollTop() < offset && stickyActive) {
$header.removeClass("sticky-active");
$('nav.top-bar.main-nav .logo-fixed').remove();
$(stickyPlaceholder).hide();
stickyActive = false;
}
if ($('body').hasClass('catalog-product-view') && Modernizr.mq('only screen and (min-width: 64.063em)')) {
setTimeout(function(){
$('.magellan-nav.magellan-fixed').css('margin-top',topbarLeftHeight+'px');
},100);
}
//HERE GOES CHANGES I AM DOING. It started to make sense how to get it working, but will this be effecient or will it have performance drawback cause of scroll event is triggered with every scroll, and same calculations will be redone again and again?
if ($('body').hasClass('catalog-product-view')) {
if ($(this).scrollTop() >= $('.product-collateral-wrapper').innerHeight()/2)
{
//will enter code here`l toggle position and top property here based on some calculations
}else{
//will toggle position and top property here based on some calculations
}
}
});
$(window).scroll();
};
私は、固定から相対への位置変更を試みました。これはページの先頭に戻り、ビューポート内では見えなくなります。
質問は表示されません。 – Shanimal
これはイメージで発生しますか? – Anthony