0

JS Fiddle
Original Idea / Another version of this question

Attention! The other version of this idea/the original idea has been answered so if the other version works for you, your welcome :)

This question is still open

So here is my new idea that I am having trouble with. I want to make an image slider. The slider has all the images inside of it and when the page turns to a hash like #home I want the slider to update to a new image. The slider is floating. The other thing is I don't want it to scroll passed other images. I just want it to scroll directly to that image. I also needs to scroll vertically since the images are different widths. I feel bad that I am basically making a job request so this is what I think is right. I can write the code if someone tells me what I need to do.

Here is the code on JS Fiddle. I just have the link so it can be worked on:

//This also need to execute when the hash is updated/an anchor link is clicked
window.onLoad = function hashLogo() {
var hash = window.location.hash;

//Image 1 Hashes
var image1 = [
    '#image1',
    '#home'
    ];

//Image 2 Hashes
var image2 = [
    '#image2',
    '#about'
    ];

if (image1.indexOf(hash) > -1) {
    //Do jQuery Sliding
}

if (image2.indexOf(hash) > -1) {
    //Do jQuery Sliding
}
};
4

1 回答 1

0

我认为您需要的是对 hashchange 事件的事件拦截:

$(window).hashchange( function(){
    // Do something when the hash changes
    // alert( location.hash );
});

如果您还使用 Ben Alman 的神话般的hashchange 插件(0.8kb),它还将确保将事件填充到不支持它的浏览器中。

于 2013-08-17T03:02:14.420 回答