Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/429.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 基于URL哈希的滑块_Javascript_Jquery_Html - Fatal编程技术网

Javascript 基于URL哈希的滑块

Javascript 基于URL哈希的滑块,javascript,jquery,html,Javascript,Jquery,Html,注意 此想法的另一个版本/原始想法已得到回答,因此,如果另一个版本适合您,欢迎:) 这个问题仍然悬而未决 因此,这是我的新想法,我有麻烦。我想制作一个图像滑块。滑块中包含所有图像,当页面变成像#home这样的散列时,我希望滑块更新为新图像。滑块是浮动的。另一件事是我不希望它滚动通过其他图像。我只想让它直接滚动到那个图像。我还需要垂直滚动,因为图像的宽度不同。我觉得很糟糕,我基本上是在提出工作要求,所以我认为这是正确的。如果有人告诉我需要做什么,我可以编写代码 下面是JS Fiddle上的代码。我


注意 此想法的另一个版本/原始想法已得到回答,因此,如果另一个版本适合您,欢迎:)

这个问题仍然悬而未决

因此,这是我的新想法,我有麻烦。我想制作一个图像滑块。滑块中包含所有图像,当页面变成像#home这样的散列时,我希望滑块更新为新图像。滑块是浮动的。另一件事是我不希望它滚动通过其他图像。我只想让它直接滚动到那个图像。我还需要垂直滚动,因为图像的宽度不同。我觉得很糟糕,我基本上是在提出工作要求,所以我认为这是正确的。如果有人告诉我需要做什么,我可以编写代码

下面是JS Fiddle上的代码。我只是有一个链接,以便可以对其进行操作:

//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
}
};

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

$(window).hashchange( function(){
    // Do something when the hash changes
    // alert( location.hash );
});
如果您还使用Ben Alman的Fableus(0.8kb),它还将确保将事件多填充到不支持它的浏览器中