我的Javascript没有';t似乎在工作(部分)
我试图给我的欢迎文本一些动画使用延迟和显示。当我在本地测试时,一切正常。然而,当我尝试在live server上运行它时,“首次加载延迟”和“jquery for front page”中的代码根本不起作用,而“responsive manipulator”部分中的代码起作用??? 如果整个脚本都不起作用,那么我可能会想出一些办法,但奇怪的是,其中有些办法起作用了 有人能告诉我发生了什么事吗 这是HTML我的Javascript没有';t似乎在工作(部分),javascript,jquery,Javascript,Jquery,我试图给我的欢迎文本一些动画使用延迟和显示。当我在本地测试时,一切正常。然而,当我尝试在live server上运行它时,“首次加载延迟”和“jquery for front page”中的代码根本不起作用,而“responsive manipulator”部分中的代码起作用??? 如果整个脚本都不起作用,那么我可能会想出一些办法,但奇怪的是,其中有些办法起作用了 有人能告诉我发生了什么事吗 这是HTML <div ng-controller="homeController" class=
<div ng-controller="homeController" class="ng-scope">
<div class="flex-box welcome">
<h1 id="line1" class="hvr-pulse">Welcome to my basement</h1>
<h3 id="line2" class="hvr-pulse">I hope these will satisfy you</h3>
<button id="welcome-button" class="hvr-grow-rotate" ng-click="about()">Allow me to introduce myself</button>
</div>
由于您正在使用angular,请将此代码放在模块中。
您正在调用代码,而元素还不在那里。您还可以包含与问题相关的HTML吗?这些元素可能不在DOM中。您可以添加一些HTML的完整图片吗?
delay()
!=setTimeout()
这两种方法完全不同,正如API明确指出的那样,延迟不是setTimeout的替代品我不太明白您想要实现什么,但作为旁注,jQuery提供了方法hasClass()
,addClass()
和removeClass()
,因此,您的if
语句应该类似于if(x.hasClass('responsive')){x.removeClass('responsive')}或者{x.addClass('responsive')}
。还请注意,它具有可选参数duration
和complete
回调,您可以使用它们来链接方法。不管怎样,你的动画在Safari上对我有用。我刚刚添加了HTML。我的错,是delay()而不是setTimeout。对于Alejandro的问题,我试图给我的元素#line1,#line2,#欢迎文本一些延迟,然后在用户首次加载页面时显示它。现在他们没有延迟(即使在本地延迟功能工作…)顺便说一句,我正在使用Chrome,也许这就是原因?
$(document).ready(function() {
// first load on delay
$('#line1').hide().delay(3000).show(2200);
$('#line2').hide().delay(5000).show(2200);
$('#welcome-button').hide().delay(10000).show(2200);
//responsive manipulator
$('.fa-bars').on('click',function () {
var x = document.getElementById("nav-bar");
if (x.className === 'nav-bar')
x.className += ' responsive';
else
x.className = 'nav-bar';
})
// jquery for front page
$('#greet').click(function() {
var audio = document.getElementById('audio');
if (audio.paused) {
audio.play();
}else{
audio.pause();
audio.currentTime = 0
}
})
});