Skip to main content

Pull to Refresh

You can create a pull-to-refresh UI using one axis.

Pull to prepend
  • egjs is Javascript components group that brings easiest and fastest way to build a web application in your way
  • egjs is Javascript components group that brings easiest and fastest way to build a web application in your way
  • egjs is Javascript components group that brings easiest and fastest way to build a web application in your way
  • egjs is Javascript components group that brings easiest and fastest way to build a web application in your way
  • egjs is Javascript components group that brings easiest and fastest way to build a web application in your way
  • egjs is Javascript components group that brings easiest and fastest way to build a web application in your way
  • egjs is Javascript components group that brings easiest and fastest way to build a web application in your way
  • egjs is Javascript components group that brings easiest and fastest way to build a web application in your way
  • egjs is Javascript components group that brings easiest and fastest way to build a web application in your way
  • egjs is Javascript components group that brings easiest and fastest way to build a web application in your way
Pull to append
<div>
<p>You can create a pull-to-refresh UI using one axis.</p>
<div id="pull-contentWrapper">
<div id="prepend">Pull to prepend</div>
<ul id="pull-content">
<li class="pull_drw">
<div class="pull_im">
<img src="../image/pulltorefresh/1.jpg" width="110"/>
</div>
<div class="pull_tx">
<span class="pull_tit">egjs is Javascript components group that brings easiest and fastest way to build a web application in your way</span>
</div>
</li>
<li class="pull_drw">
<div class="pull_im">
<img src="../image/pulltorefresh/2.jpg" width="110"/>
</div>
<div class="pull_tx">
<span class="pull_tit">egjs is Javascript components group that brings easiest and fastest way to build a web application in your way</span>
</div>
</li>
<li class="pull_drw">
<div class="pull_im">
<img src="../image/pulltorefresh/3.jpg" width="110"/>
</div>
<div class="pull_tx">
<span class="pull_tit">egjs is Javascript components group that brings easiest and fastest way to build a web application in your way</span>
</div>
</li>
<li class="pull_drw">
<div class="pull_im">
<img src="../image/pulltorefresh/4.jpg" width="110"/>
</div>
<div class="pull_tx">
<span class="pull_tit">egjs is Javascript components group that brings easiest and fastest way to build a web application in your way</span>
</div>
</li>
<li class="pull_drw">
<div class="pull_im">
<img src="../image/pulltorefresh/5.jpg" width="110"/>
</div>
<div class="pull_tx">
<span class="pull_tit">egjs is Javascript components group that brings easiest and fastest way to build a web application in your way</span>
</div>
</li>

<li class="pull_drw">
<div class="pull_im">
<img src="../image/pulltorefresh/6.jpg" width="110"/>
</div>
<div class="pull_tx">
<span class="pull_tit">egjs is Javascript components group that brings easiest and fastest way to build a web application in your way</span>
</div>
</li>
<li class="pull_drw">
<div class="pull_im">
<img src="../image/pulltorefresh/7.jpg" width="110"/>
</div>
<div class="pull_tx">
<span class="pull_tit">egjs is Javascript components group that brings easiest and fastest way to build a web application in your way</span>
</div>
</li>
<li class="pull_drw">
<div class="pull_im">
<img src="../image/pulltorefresh/8.jpg" width="110"/>
</div>
<div class="pull_tx">
<span class="pull_tit">egjs is Javascript components group that brings easiest and fastest way to build a web application in your way</span>
</div>
</li>
<li class="pull_drw">
<div class="pull_im">
<img src="../image/pulltorefresh/9.jpg" width="110"/>
</div>
<div class="pull_tx">
<span class="pull_tit">egjs is Javascript components group that brings easiest and fastest way to build a web application in your way</span>
</div>
</li>
<li class="pull_drw">
<div class="pull_im">
<img src="../image/pulltorefresh/10.jpg" width="110"/>
</div>
<div class="pull_tx">
<span class="pull_tit">egjs is Javascript components group that brings easiest and fastest way to build a web application in your way</span>
</div>
</li>
</ul>
<div id="append">Pull to append</div>
</div>
<div class="bottomWapper"></div>
</div>
const contentWrapper = document.getElementById("pull-contentWrapper");
const content = document.getElementById("pull-content");
const prepend = document.getElementById("prepend");
const append = document.getElementById("append");

function getInfo(pos) {
const state = pos > 0 ? (pos - axes.axis.scroll.range[1])/100 : -pos/100;
return {
isAdd: state > 0.8,
isTop: pos < 0,
};
}

function getMaxRange() {
return content.getBoundingClientRect().height - contentWrapper.getBoundingClientRect().height
}

function getItem() {
const el = document.createElement("li");
el.className = "pull_drw addblinking";
el.innerHTML = `<div class="pull_im">
<img src="../image/pulltorefresh/${Math.floor((Math.random() * 50) + 1)}.jpg" width="110"/>
</div>
<div class="pull_tx">
<span class="pull_tit">egjs is Javascript components group that brings easiest and fastest way to build a web application in your way</span>
</div>`;
return el;
}

// 1. Initialize eg.Axes
const axes = new eg.Axes({
scroll: {
range: [0, getMaxRange()],
bounce: 100
}
});

// 2. attach event handler
axes.on({
"change": ({pos}) => {
content.style[eg.Axes.TRANSFORM] = `translate3d(0, ${-pos.scroll}px, 0)`;
if (axes.isBounceArea()) {
const info = getInfo(pos.scroll);
if (info.isAdd) {
info.isTop ? (prepend.innerText = "Release to prepend") :
(append.innerText = "Release to append");
} else {
info.isTop ? (prepend.innerText = "Pull to prepend") :
(append.innerText = "Pull to append");
}
}
},
"release" : ({depaPos}) => {
if (axes.isBounceArea()) {
const info = getInfo(depaPos.scroll);
if (info.isAdd) {
const el = getItem();
info.isTop ?
content.insertBefore(el, content.firstChild) :
content.appendChild(el);
axes.axis.scroll.range[1] = getMaxRange();
}
}
}
});

// 3. Initialize inputTypes and connect it
axes.connect(["", "scroll"], new eg.Axes.PanInput(contentWrapper, {
scale : [0, -1]
}));