Hook. js-pull-down and refresh effects on mobile phones on traditional Web pages

Source: Internet
Author: User

We all like the "pull-down refresh" function on mobile devices. What if this effect is applied to traditional web pages? Well, Hook. js can be implemented. They used this innovation in mobile phones and tablets. As long as they scroll down and then bounce back to the top, the page will automatically refresh.

Articles you may be interested in
  • Use Toolbar. js to implement a cool Tooltip style Toolbar
  • Textillate. js-Simple plug-in for CSS 3 text Animation
  • Use ThreeSixty to create a 360-degree panoramic image Preview
  • Practical Tips: We recommend a great responsive Web Testing Tool.
  • Impressive jQuery modal box plug-in-iLightBox

 

 

Download the source code for Online demonstration (Wall-over required)

 

Hook. js is very simple to use. first introduce the following three files:

<script src="http://code.jquery.com/jquery-latest.js" type="text/javascript"></script><link rel="stylesheet" href="hook/hook.css" type="text/css" /><script src="hook/hook.js" type="text/javascript"></script>

Put the following HTML code in the <body> tag:

<div id="hook"><div id="loader"><div class="spinner"></div></div><span id="hook-text">Reloading...</span></div>  

The implementation of Hook. js is actually very simple. The complete source code is as follows:

$(function () {    window.loadheight = $('#hook').height();    window.hidden = $("#hook").animate("marginTop", "-" + loadheight + "px");    window.visible = $("#hook").animate("marginTop", "0px");    $("#hook").css("marginTop", "-" + loadheight + "px")});$(function hook() {    var loadheight = $('#hook').height();    $(window).scroll(function (event) {        var st = $(window).scrollTop();        if (st <= 0) {            $("#hook").animate({                "marginTop": "0px"            }, 200);            $("#hook").delay(500).slideUp(200, function () {                window.location.reload()            })        }        if ($.browser.webkit) {            if (st == 0) {                $('body').css('overflow', 'hidden')            }        }    })});

 

Articles you may be interested in
  • Respond. js-make IE6-8 support CSS3 Media Query
  • Debuggex-Excellent visual debugging tool for Regular Expression
  • Front-end digest-practical tools and tips for optimizing Web Images
  • Lazy Line Painter-interesting jQuery path animation plug-in
  • Zepto. js-a lightweight JavaScript library for modern browsers

 

Link to this article: Hook. js-pull-down and refresh effects on mobile phones on traditional Web pages

Source: Dream sky ◆ focus on Web Front-end development technology ◆ share Web design resources

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.