var clientHeight = $(window).height(); window.onscroll = function(){ var top = document.getElementsByClassName("bottom")[0].getBoundingClientRect().top; console.log(top); if(top < clientHeight){ $("div.go_crash").css("position", "relative"); }else{ if($("div.go_crash").css("position") == "relative"){ $("div.go_crash").css("position", "fixed"); } } };
document.getElementsByClassName("bottom")須要作判斷的元素
$("div.go_crash") 實際須要變換位置的元素