[英]JQuery animate to a position based on vw
I have a title whos position from the top of the page is based on margin-top with a vw value.我有一个标题,其从页面顶部的位置基于带有 vw 值的 margin-top。
.name_slogan {
width: 1000px;
margin: auto;
z-index: 1;
margin-top:7vw;
}
I'd like this title to move in from above and then have the title margin-top behave as a vw normally would.我希望这个标题从上方移入,然后让标题 margin-top 表现得像普通大众一样。 Meaning it grows and shrinks as the window is resized.这意味着它会随着窗口大小的调整而增长和缩小。
So far, I have moved the div off the page on page load:到目前为止,我已经在页面加载时将 div 移出了页面:
$('.name_slogan').css({
position: 'relative',
top: '-300px'
});
And then I can bring it back on to a set position:然后我可以把它恢复到一个固定的位置:
$('.name_slogan').animate({top: "200px"}, 5000);
But then, of course, vw does not work.但是,当然,vw 不起作用。 So if possible, I'd like something like this non working code:所以如果可能的话,我想要这样的非工作代码:
$('.name_slogan').animate({top: "7vw"}, 5000);
jQuery 可以自行访问您的视口尺寸 - 您应该能够做到
$('.name_slogan').animate({top: $(window).width()*0.07}, 5000);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.