好吧,假设我正在为我的 div 使用以下设置:
.background将包含一个图像。
.overlay会有一个半透明的白色背景作为覆盖层,
.inner会有效地屏蔽掉 div 大小的矩形吗?使背景透明并穿过覆盖层 div。
<div class="background">
<div class="overlay">
<div class="inner">
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
只用CSS可以实现吗?
我使用以下代码为我的站点上的锚添加平滑滚动。因为我有一个粘性标头ID,想将其偏移200像素
$('a[href*="#"]:not([href="#"])').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if (target.length) {
$('html, body').animate({
scrollTop: target.offset().top
}, 1000);
return false;
}
}
});
Run Code Online (Sandbox Code Playgroud)