Giter VIP home page Giter VIP logo

tjax's Introduction

tjax

Asynchronous page replacement JavaScript library using Ajax and pushState.

Download

tjax.js

Demo

https://totoraj930.github.io/tjax

Usage

Basic

<!DOCTYPE html>
<html lang="en">
<head>
    <title>tjax</title>
    <script src="tjax.js"></script>
    <script>
        var tjax = new Tjax();

        if (!tjax.isSupported()) return;

        document.addEventListener("click", function (event) {
            var target = event.target;
            if (target.hasAttribute("data-tjax")) {
                event.preventDefault();
                event.stopPropagation();
                tjax.load(target.href);
                return false;
            }
        });
    </script>
</head>
<body>
    <a href="./page2.html" data-tjax>Go to page2</a>
</body>
</html>

API

Tjax.setOptions

Set the option.

See Options.

tjax.setOptions({
    areas: ["#replace_area", "#foot"],
    wait: 400
});

Tjax.load

Load the page according to the option and replace the elements.

tjax.load("./page-2.html");

Tjax.isSupported

Return whether it supports browsers.

tjax.isSupported();

Options

Name Description Default
areas Selector array of elements to replace ["body"]
wait Wait time to replace(ms) 0
changeTitle Whether to change the title true
loadScript Whether to load the script true
controlScroll Whether to control the scroll true
waitPopState Whether to use "wait" for "onpopstate". true
onErrorNotMove Please feel it!!!(I can not write English!!!) false

Events

All events dispatch to "document".

Name Description
tjax:start When processing is started
tjax:loaded When XMLHttpRequest completed
tjax:error When an error occurs
tjax:end When processing is completed

Supported Browsers

  • Google Chrome
  • Firefox
  • IE10+
  • Edge

Do not know

  • Safari

Author

Reona Oshima (totoraj)

License

Copyright © 2017 Reona Oshima (totoraj)
This work is released under the MIT License.
http://opensource.org/licenses/mit-license.php

tjax's People

Contributors

totoraj930 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.