我用简单的Jquery创建了一个基本的弹出窗口,而不是滚动到窗口高度的弹出窗口。是否可以将弹出窗口滚动到用户视图位置?谢谢。
$(document).scroll(function(){
if (!$("#mc_embed_signup").data('userClosed')) {
$(".popup-close").click(function(e){
closeSPopup(e);
});
var a = $(this).scrollTop();
if (a > 350) {
$("#mc_embed_signup").show().animate({top: (window.innerHeight / 2 - 0) + "px"}, 1800);
}
}
});
function closeSPopup(e){
e.preventDefault();
$("#mc_embed_signup").data('userClosed',true);
$("#mc_embed_signup").hide();
};发布于 2018-03-20 08:06:38
你可以使用css过渡得到你想要的效果
<style>
#mc_embed_signup {
position: fixed;
top: -500px; //position offscreen; must be at least size of the
popup
-webkit-transition: all 1.8s ease;
-moz-transition: all 1.8s ease;
-o-transition: all 1.8s ease;
transition: all 1.8s ease;
}
</style>
$(document).ready(function() {
window.onscroll = function () { scrollFunction(); };
scrollFunction() {
var scrollPosition = document.documentElement.scrollTop;
if (scrollPosition > 350) {
$("#mc_embed_signup").show().css("top", (window.innerHeight /
2 - 0).toString());
}
}
});https://stackoverflow.com/questions/49373541
复制相似问题