[英]Add Offset Y "-100px" when I click on an anchor and it scrolls me down to an element
[英]Fade an image out (down-arrow) when a user scrolls 100px or so down my webpage
当前,使用css,箭头图像位于屏幕底部。 我在屏幕上使用的图像
<img class="down-arrow" src="pathtoimg"/>
该按钮是白色的向下箭头,周围带有黑色圆圈,不透明度设置为40%。 我想拥有自己的主屏幕来通知访问者向下滚动。 当他们向下滚动时,我希望它消失。 无论用户在其上观看显示器的大小如何,我都希望它在屏幕底部。 我应该怎么做? 我正在运行wordpress和beaver构建器。 不太熟悉jquery / javascript。
(编辑:我也做了此按钮,因此当您单击它时,它会将您带到页面上的预定位置。它使用以下链接:
<a href="locationtojumpto"><img "codestuffhere"/></a>
)
这是我用来保持图片居中并位于网站底部的CSS:
.down-arrow {
position: fixed;
bottom: 1%;
left: 50%; }
我尝试了另一页上的jquery,但我不知道如何将其合并到网站中。 我正在使用海狸生成器,并且尝试过使用工具,然后布局css / javascript,并将其放在javascript下,但是没有用。 当用户滚动100像素后图像消失时,我也不会介意。
这是我使用的jQuery,但老实说,我不知道它的功能或使用方法,放置位置或其他任何内容。
$(window).scroll(function(){
$(".down-arrow").css("opacity", 1 -
$(window).scrollTop() / 100);
});
我把它放在javascript下的beaver构建器工具中,但我不认为它在那里,也不知道如何使它在图像上运行。 我是一个极端的初学者,请放松一下。 :(
我以这支笔为例。 请享用。
http://codepen.io/StevenVentimiglia/pen/PzQPxV
的HTML
<div id="mainContainer">
<button class="btn">This is a button.</button>
</div>
的CSS
body {
background: #999;
}
#mainContainer {
position: relative;
text-align: center;
height: 2400px;
background: #eee;
}
#mainContainer button.btn {
width: 200px;
height: 40px;
position: fixed;
top: 40px;
left: 50%;
color: #333;
font-size: 16px;
margin-left: -100px;
}
JS
// Scroll Control
$(window).scroll(function() {
if ($(document).scrollTop() > 400) {
$('.btn').hide();
} else {
$('.btn').show();
}
});
$('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;
}
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.