.thumbnail
要素をクリックすると、click()
イベントが発生$(this).attr('id')
し、ハッシュ/スクロールに使用されます。ページの読み込み時にこれを実行するには、ID をパラメーターとして受け取る別の関数に分割し、click()
イベントからこの関数を呼び出すだけでなく、 のパラメーターを使用して一般的なページの読み込みを行う必要がありますlocation.hash
。
$(document).ready(function(){
if (location.hash.length>0){
/* this assumes the page to load is the only thing in the
hash, for example /page.php#project.html */
var hash = location.hash.substring(1); // get hash and remove #
addHashAndScroll(hash); // call function with page name
}
$('.thumbnail').click(function() {
addHashAndScroll($(this).attr('id')); // pass ID value to function
});
}
// this function contains most of your original script
function addHashAndScroll(id){
var idStr = "project/"+ id + "#projectcontainer";
// rest of your code
}
更新: これは js に関するもので、説明するとすべて意味がありますが、実行するのは雌犬です。とにかく、助けてくれてありがとう。あなたの説明に基づいて、私が得るものは次のとおりです。
$(document).ready(function() {
if (location.hash.length > 0) {
/* this assumes the page to load is the only thing in the
hash, for example /page.php#project.html */
var hash = location.hash.substring(1); // get hash and remove #
addHashAndScroll(hash); // call function with page name
}
$('.thumbnail').click(function() {
addHashAndScroll($(this).attr('id')); // pass ID value to function
});
}
// this function contains most of your original script
function addHashAndScroll(id) {
var idStr = "project/" + id + "#projectcontainer";
$('#projectcontainer').animate({
opacity: 0
});
$('#projectcontainer').hide().load(idStr, function() {
$(this).slideDown(500).animate({
opacity: 1
}, function() {
$.scrollTo('#gohere', 800);
$('#close').fadeIn(500).css({
'display': 'block',
'height': '25px'
});
});
});
}
私はクロージャーとバグテストjsでの最小限の経験をいじろうとしましたが、次の行からエラーが発生し続けます: function addHashAndScroll(id) {