问题描述
首先,这是我讨厌的
因此,只要散列值发生变化,我就会使用jQuery淡入淡出效果来替换此图像。我想要它也检查onLoad上的散列。现在我有一个疯狂的代码,我很肯定不起作用,因为我是一种新的Javascript开发人员。这是一个可怕的代码。
如果代码正常工作,它会这样做:
//主页哈希
var home = [
#home,
#news,
#team ,
#cont,
#about,
#FAQ];
它会检查每个数组中的哈希,如果它在一个数组中找到匹配,它会淡出当前图像,将它们切换出来,并淡入新图像。根据它所在的阵列,它会选择不同的图像。
(顺便说一句,当更改图像时,它正在改变html中的src。)
我使用这个来改变我的logo你在网站上。
您需要使用onload加hashchange
window.onload = checkHash;
window.onhashchange = checkHash;
函数checkHash(){
//检查东西
}
Working Fiddle ::仔细 hash
确实会改变: - )
First, here is my crazy code that you will hate
So I have this image that I want to replace with a jQuery fade effect whenever the hash changes. I want for it to check the hash on onLoad too. Right now I have a crazy code that I am pretty sure doesn't work because I am a kind of new Javascript developer. It is a horrible code.
If the code worked, it would do this:
//Home Hashes
var home = [
"#home",
"#news",
"#team",
"#cont",
"#about",
"#FAQ"];
It would check for for the hashes in each of these arrays, if it finds a match in one array, it will fade out the current image, switch them out, and fade the new image in. Depending on what array it is in, it will choose a different image.
(BTW, when changing the image it is changing the src in the html.)
I am using this to change my logo based on where you are on the site. My site has different logos for different sections.
You need to use onload plus hashchange
window.onload = checkHash;
window.onhashchange = checkHash;
function checkHash() {
// check stuff
}
Working Fiddle :: careful hash
does change :-)
这篇关于根据散列淡出并用其他图像替换图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!