mirror of
https://github.com/ruanyf/es6tutorial.git
synced 2025-05-27 20:32:21 +00:00
Merge branch 'gh-pages' of github.com:ruanyf/es6tutorial into gh-pages
This commit is contained in:
commit
9322419906
@ -45,7 +45,7 @@ Promise实例生成以后,可以用then方法分别指定Resolved状态和Reje
|
|||||||
```javascript
|
```javascript
|
||||||
promise.then(function(value) {
|
promise.then(function(value) {
|
||||||
// success
|
// success
|
||||||
}, function(value) {
|
}, function(error) {
|
||||||
// failure
|
// failure
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
39
js/ditto.js
39
js/ditto.js
@ -18,6 +18,30 @@ var ditto = {
|
|||||||
run: initialize
|
run: initialize
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前hash
|
||||||
|
*
|
||||||
|
* @param {string} hash 要解析的hash,默认取当前页面的hash,如: nav#类目 => {nav:nav, anchor:类目}
|
||||||
|
* @description 分导航和页面锚点
|
||||||
|
* @return {Object} {nav:导航, anchor:页面锚点}
|
||||||
|
*/
|
||||||
|
var getHash = function (hash) {
|
||||||
|
hash = hash || window.location.hash.substr(1);
|
||||||
|
|
||||||
|
if (!hash) {
|
||||||
|
return {
|
||||||
|
nav: '',
|
||||||
|
anchor: ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
hash = hash.split('#');
|
||||||
|
return {
|
||||||
|
nav: hash[0],
|
||||||
|
anchor: decodeURIComponent(hash[1] || '')
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
var disqusCode = '<h3>留言</h3><div id="disqus_thread"></div>';
|
var disqusCode = '<h3>留言</h3><div id="disqus_thread"></div>';
|
||||||
var menu = new Array();
|
var menu = new Array();
|
||||||
|
|
||||||
@ -56,16 +80,18 @@ function init_sidebar_section() {
|
|||||||
menu.push(this.href.slice(this.href.indexOf('#')));
|
menu.push(this.href.slice(this.href.indexOf('#')));
|
||||||
});
|
});
|
||||||
$('#pageup').on('click', function() {
|
$('#pageup').on('click', function() {
|
||||||
|
var hash = getHash().nav;
|
||||||
for (var i = 0; i < menu.length; i++) {
|
for (var i = 0; i < menu.length; i++) {
|
||||||
if (location.hash === '') break;
|
if (hash === '') break;
|
||||||
if (menu[i] === location.hash) break;
|
if (menu[i] === '#' + hash) break;
|
||||||
}
|
}
|
||||||
location.hash = menu[i - 1]
|
location.hash = menu[i - 1]
|
||||||
});
|
});
|
||||||
$('#pagedown').on('click', function() {
|
$('#pagedown').on('click', function() {
|
||||||
|
var hash = getHash().nav;
|
||||||
for (var i = 0; i < menu.length; i++) {
|
for (var i = 0; i < menu.length; i++) {
|
||||||
if (location.hash === '') break;
|
if (hash === '') break;
|
||||||
if (menu[i] === location.hash) break;
|
if (menu[i] === '#' + hash) break;
|
||||||
}
|
}
|
||||||
location.hash = menu[i + 1];
|
location.hash = menu[i + 1];
|
||||||
});
|
});
|
||||||
@ -347,14 +373,13 @@ function router() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (location.hash === '' || '#' + getHash().nav === menu[0]) {
|
||||||
if (location.hash === '' || location.hash === menu[0]) {
|
|
||||||
$('#pageup').css('display', 'none');
|
$('#pageup').css('display', 'none');
|
||||||
} else {
|
} else {
|
||||||
$('#pageup').css('display', 'inline-block');
|
$('#pageup').css('display', 'inline-block');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (location.hash === menu[(menu.length - 1)]) {
|
if ('#' + getHash().nav === menu[(menu.length - 1)]) {
|
||||||
$('#pagedown').css('display', 'none');
|
$('#pagedown').css('display', 'none');
|
||||||
} else {
|
} else {
|
||||||
$('#pagedown').css('display', 'inline-block');
|
$('#pagedown').css('display', 'inline-block');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user