Open Cart 里滚屏显示/粘滞的代码

Open Cart 里滚屏显示/粘滞的代码

catalog/view/javascript/common.js

$(function(){
	var div = '#supermenu';
	var windowScrollTop = $(window).scrollTop();
	var divOffsetTop = $(div).offset().top;
	if(windowScrollTop > divOffsetTop){
		$(div).addClass('sticky');
	} else {
		$(div).removeClass('sticky');
	}

	$(window).on('scroll', function(){
		var windowScrollTop = $(window).scrollTop();
		if(windowScrollTop > divOffsetTop){
			$(div).addClass('sticky');
		} else {
			$(div).removeClass('sticky');
		}
	});
});

catalog/view/theme/default/stylesheet/stylesheet.css


#supermenu.sticky {
	position: fixed;
	left: 0;
	right: 0;
	top: 0;
	z-index: 999999;
}

HTML 部分自己加ID了

分享这篇文章