This article mainly introduces how to share the sliding effect of javascript to Page scrolling. The example shows how to perform page element scrolling in javascript, if you need it, refer to the examples in this article to describe how to share the js to slide with Page scrolling. Share it with you for your reference. The details are as follows:
The page scroll up and down, and the shared module slides.
Key points:
The Code is as follows:
Var scrtop upload document.doc umentElement. scrollTop | document. body. scrollTop;
Var height = document.doc umentElement. clientHeight | document. body. clientHeight;
Var top = scrtop + (height-jb51.offsetHeight)/2;
Top = parseInt (top );
Obtain the vertical center position of the page
Code:
Untitled documentScript window. onload = function () {var jb51 = document. getElementById ("jb51"); jb51.onmouseover = function () {startrun (jb51, 0, "left")} jb51.onmouseout = function () {startrun (jb51,-100, "left")} window. onscroll = window. onresize = function () {var scrtop=document.doc umentElement. scrollTop | document. body. scrollTop; var height1_document.doc umentElement. clientHeight | document. body. clientHeight; var top = Scrtop + (height-jb51.offsetHeight)/2; top = parseInt (top); startrun (jb51, top, "top")} var timer = nullfunction startrun (obj, target, direction) {clearInterval (timer); timer = setInterval (function () {var speed = 0; if (direction = "left") {speed = (target-obj.offsetLeft)/8; speed = speed> 0? Math. ceil (speed): Math. floor (speed); if (obj. offsetLeft = target) {clearInterval (timer);} else {obj. style. left = obj. offsetLeft + speed + "px" ;}} if (direction = "top") {speed = (target-obj.offsetTop)/8; speed = speed> 0? Math. ceil (speed): Math. floor (speed); if (obj. offsetTop = target) {clearInterval (timer);} else {obj. style. top = obj. offsetTop + speed + "px";} document. title = obj. offsetTop + ',' + target + ',' + speed ;}, 30)} scriptShare to content share
I hope this article will help you design javascript programs.