爲了讓Google友好,我想稍微更改一下這個腳本。使用jQuery循環顯示#anchor而不是URL中的索引
我有一個頁面佈局,我使用jQuery Cycle在內容之間進行動畫製作。現在,該腳本將在URL中顯示當前幻燈片的編號。防爆。 「index.html#1」或「index.html#4」。它看起來可怕的,我認爲谷歌會想太多... ;-)
我希望它顯示的div #anchor而不是它的指數,所以網址將是「的index.html#項目」,而不是
HTML菜單:
<div id="menu">
<ul>
<li><a href="#About">About</a></li>
<li><a href="#Projects">Projects</a></li>
<li><a href="#Learning">Learning</a></li>
</ul>
</div>
腳本:
//Set .active to current page link
var url = location.hash.slice(1);
if (url < 1) {
$("#menu li:nth-child(" + (location.hash.slice(1) - 1) + ") a ").addClass("active");
}
//Slide effect
$('#logo').click(function() {
$('.slideshow').cycle(0);
return false;
});
$('#menu li a').click(function() {
$('.slideshow').cycle($(this).parent().index()+1);
return false;
});
$('.slideshow').cycle('pause');
var index = 0, hash = window.location.hash;
if (hash) {
index = /\d+/.exec(hash)[0];
index = (parseInt(index) || 1) - 1; // slides are zero-based
}
$('.slideshow').cycle({
fx: 'blindY', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
speed: 700,
startingSlide: index,
cleartype: 1,
timeout: 3000,
after: function(curr,next,opts) {
window.location.hash = opts.currSlide + 1;
}
});
是它有可能使其顯示divs #anchor而不是其索引?
預先感謝您... :-)
謝謝。我怎樣才能使其相反?所以當我輸入URL中的#about時,幻燈片會顯示?你知道嗎? – 2011-02-14 11:41:50