我使用此代码在滚动页面时移动项目
$(document).scroll(function() {
var scrollTop = window.pageYOffset || document.documentElement.scrollTop;
$("#profile").offset({top:scrollTop+34});
});
此代码用于显示和隐藏它。
$(document).ready(function() {
$(".various[type=profile]").click(function() {
if($("#profile").attr("clicked") == "yes") {
$("#profile").stop().animate({opacity: 0}, 1000);
setTimeout(function(){$("#profile").css("visibility", "hidden")}, 1000);
$("#profile").attr("clicked", "");
}
else {
$("#profile").css("visibility", "visible");
$("#profile").stop().animate({opacity: 1}, 1000);
$("#profile").attr("clicked", "yes");
}
});
});
这是CSS
#profile {
position: absolute;
top: 34px;
right: 0;
width: 200px;
visibility: hidden;
z-index: 1000;
opacity: 0;
}
问题是每次点击该项目都会返回到其初始位置(顶部:34px,右侧:0px)。使用 fadeIn/fadeOut 我也遇到同样的问题。
最佳答案
关于javascript - 拖动项目和 jquery 动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18000984/