How to realize the effect of right suspension frame by JS
This article mainly shows you "JS how to achieve the right suspension box effect", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "JS how to achieve the right side suspension box effect" this article.
The details are as follows
Keep a div suspended in the lower right corner all the time
Document # div1 {width: 100px; height: 150px; background: red; position: absolute; bottom: 0px; right: 0px } _ window.onscroll = function () {var oDiv = document.getElementById ('div1'); var scrollTop = document.documentElement.scrollTop | document.body.scrollTop;// browser is compatible with startmove (document.documentElement.clientHeight-oDiv.offsetHeight + scrollTop) / / document.documentElement.clientHeight page visual area height} var timer = null / / suspension frame buffer movement function startmove (iTarget) {var oDiv = document.getElementById ('div1'); clearInterval (timer); timer = setInterval (function () {var speed = (iTarget-oDiv.offsetTop) / 4 Speed = speed > 0?Math.ceil (speed): Math.floor (speed); if (oDiv.offsetTop = = iTarget) {clearInterval (timer);} else {oDiv.style.top = oDiv.offsetTop + speed+'px' }, 30)} couplet suspension
Let div float in the middle of the right.
You just need to change the data in the start move () function
I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!