美文网首页前端Web前端之路让前端飞
js滚动到一定氛围内显示超出隐藏

js滚动到一定氛围内显示超出隐藏

作者: 花花0825 | 来源:发表于2017-10-19 09:27 被阅读16次

html:

<div id="MM"></div>


css:

body{

height: 3000px;

}

#MM{

width: 100px;

height: 100px;

background-color: red;

position: fixed;

top: 200px;

right: 10px;

display: none;

}


js:

1:引入jq库

2:

$(document).ready(function () {

$(window).scroll(function () {

if ($(document).scrollTop() > 600 &&$(document).scrollTop() < 2000) {

$("#MM").css({ "position":"fixed","bottom":"0px","display":"block"})

}

else if ($(document).scrollTop() >= 2000) {

$("#MM").css({ "position":"absolute","bottom":"110px","display":"block"})

}

else {

$("#MM").css({ "display":"none"})

}

});

});

相关文章

网友评论

    本文标题:js滚动到一定氛围内显示超出隐藏

    本文链接:https://www.haomeiwen.com/subject/jlzyuxtx.html