Floating announcement-simple jquery implementation

Source: Internet
Author: User

This is a problem encountered when the examination system was maintained some time ago, that is, the floating examination announcement. At that time, neither JS nor jquery had been learned. Based on the original functions, it was implemented based on the Huludao scheme. However, I didn't know much about the details. I just learned JavaScript and came into contact with jquery, So I re-commented on this function.

Interface:


Head:

<Title> floating announcement </title> <SCRIPT src = "JS/jquery. JS "type =" text/JavaScript "> </SCRIPT> <link href =" CSS/exatman.css "rel =" stylesheet "type =" text/CSS "/>

Body:

<Div id = "examinfo" runat = "server"> welcome to the online examination system <HR/> <asp: label id = "lblstudentname" runat = "server"> </ASP: Label> <HR/> remaining time: <asp: textbox id = "txttime" runat = "server" enabled = "false"> </ASP: textbox> <HR/> Read the exam carefully. Note: <br/> <asp: Label id = "lblexaminationinstruction" runat = "server" forecolor = "red"> </ASP: label> <br/> <HR/> </div>

Javascript:

<SCRIPT type = "text/JavaScript"> $ (function () {// defines the jquery object var $ sidebar =$ ("# examinfo") of examinfo Based on the ID selector "), $ window = $ (window), // obtain the relative offset of examinfo in the current window = $ sidebar. offset (), // custom, as offset toppadding = 15; // bind rolling event $ window. scroll (function () {if ($ window. scrolltop ()> offset. top) {// determine the current position. If the offset relative to the top of the scroll bar is greater than the offset to the window, adjust the outer margin $ sidebar. stop (). animate ({// reposition examinfo margintop: $ window. scrolltop ()-offset. top + toppadding});} else {// if the current offset relative to the top of the scroll bar is less than the offset to the window, the top margin is zero // custom animation, the specified property must be in the form of $ sidebar. stop (). animate ({margintop: 0}) ;}}) ;}); </SCRIPT>

Running result:The announcement can be dynamically positioned to the top left of the page as the scroll bar moves.

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.