Javascript tips-javascript tips

Source: Internet
Author: User
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)} script

Share to content share

I hope this article will help you design javascript programs.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.