2014-04-22 130 views
0

我正尝试在我创建的初始页面上创建一个淡入淡出,并将其融入到我的网站的主页面中。我的网站是:http://www.simonsamuel.com/淡入淡出页面

我使用jQuery的代码是:

<script type="text/javascript"> 
    $("#splash").click(function() { 
     $("#splash").fadeOut("slow"); 
    }); 
</script> 

这里是CSS代码:

#splash { 
    background-color: #ffffff; 
    background-image: url(http://i.imgbox.com/Al4c3tZ5.png); 
    background-position: center; 
    background-repeat: no-repeat; 
    position: fixed; 
    top: -60px; 
    right: 0; 
    bottom: 0; 
    left: 0; 
    z-index: 99999; 
} 

我已经尝试了许多不同的代码,但我的找不到与我的网站一起工作的人。出于好奇,我想知道是否有可能用jQuery改变网页标题?我想制作标题栏大写字体。

帮助将不胜感激,谢谢!

+0

你使用jquery –

+0

你的代码没有问题,是的,你可以用jQuery来改变网页标题。人们可能不愿意访问外部链接并挖掘您的源代码,以了解#splash是什么以及它是如何设置的。最后一件事,把你的代码放在文档就绪处理程序中:$(document).ready(function(){... yourcode here ...}); –

+0

你的jQuery代码工作正常http://jsfiddle.net/你加载jQuery库吗? – Maggz

回答

0

我成立了一个小提琴证明的基础 - http://jsfiddle.net/jayblanchard/nBdkU/

$(document).ready(function() { 
    $('#splash').css('opacity', '0.5'); // doing this with jQuery for ease 

    // here are the basics, just like your existing code 
    $("#splash").click(function() { 
     $("#splash").fadeOut("slow"); // you could also use $(this).fadeOut('slow'); 
    }); 
}); 

看着控制台加载你的页面时,我得到一个指向语法错误@ Puzzle84指出的同样的问题 -

<script type="text/javascript"><br /> 
$(document).ready(function() {<br /> 
$('#splash').click(function() {<br /> 
    $('#splash').fadeOut(2000);<br /> 
    });<br /> 
</script> 

所有这些换行符都需要删除。然后,正如他指出的那样,您需要另一组右括号(});)在关闭脚本标记之前。当我点击splash元素时,它会消失,并显示您的网站。如果你有想要在splash元素中展示的东西,那么你只需要为这些元素获取CSS定位。

也有其他错误,在控制台中指出(没有定义Cargo.View.Main)

为标题位,你可以做一些纯JavaScript或少许的jQuery -

document.title = 'the page title'; // changes the title 
document.title.toUpperCase(); // sets title to upper case 

$(document).attr('title', 'the page title'); // changes the title 
$(document).attr('title').toUpperCase(); // sets to upper case 
+0

我试过你提供的不透明代码工作的代码,但淡入淡出的代码不起作用。当我输入代码时,没有放置“
”。我认为该网站将自动放置此网站。标题代码也不起作用。 – Simon

+0

如果网站自动将其放置在那里(并且摆脱大括号),那么会出现问题,因为它会导致导致jQuery失败的语法错误。也许你需要与网站管理员交谈? –

+0

@Simon我现在在代码中看到一大堆反斜杠,就像有人试图为某些东西转义角色。另外 - 在源代码中加载jQuery的位置在哪里?我找不到它。你的jQuery代码没有工作,但我不知道这是不是因为jQuery没有加载? –

1

当我看到你的源代码,我看到这一点:

<br /> 
$(document).ready(function() {<br /> 
    $('#splash').click(function() {<br /> 
     $('#splash').fadeOut(2000);<br /> 
    });<br /> 

为什么会出现在换行代码? 这就是html代码。

除了你的代码是不完整的

$(document).ready(function() { 
    $('#splash').click(function() { 
     $('#splash').fadeOut(2000); 
    }); // forgot these 
}); // or these 
+0

我试着改变它,它仍然不起作用,我在Cargo Collective上托管。我不知道为什么我遇到这个问题 – Simon

+0

@Simon当我今天早上看代码时,我没有看到这些变化。你确定你上传了吗? –