我创建了一个自动滑动的旋转木马每5秒钟(以及手动按钮移动幻灯片).我希望能够在鼠标悬停在幻灯片上时暂停滚动,并在鼠标不再悬停时恢复.
到目前为止,我的脚本将执行以上所有操作.
但是它不会在页面加载时启动,您必须将鼠标悬停在然后取消悬停才能启动.
这是我的脚本:
jQuery('#viewport').hover(function () {
window.clearInterval(timer);
}, function () {
timer = window.setInterval(function () {
jQuery('#next').trigger('click');
}, 1000);
});
Run Code Online (Sandbox Code Playgroud)
我该怎么做才能让它立即开始滑动?
我正在尝试根据控制器中的Javascript Date对象在视图中显示当前时间.我的控制器看起来像这样:
myApp.controller('DateCtrl', function($scope) {
var date = new Date();
$scope.minutes = date.getMinutes();
$scope.hours = date.getHours();
$scope.seconds = date.getSeconds();
var updateTime = function() {
var date2 = new Date();
$scope.minutes = date2.getMinutes();
$scope.hours = date2.getHours();
$scope.seconds = date2.getSeconds();
}
$scope.clickUpdate = function() {
setInterval(updateTime, 1000);
}
});
Run Code Online (Sandbox Code Playgroud)
在我看来,我只是:
<div ng-controller="DateCtrl">
<div>This is the hour: {{ hours }}</div>
<div>This is the minute: {{ minutes }}</div>
<div>This is the second: {{ seconds }}</div>
<button ng-click="clickUpdate()">Click Update Here!</button>
</div>
Run Code Online (Sandbox Code Playgroud)
由于某种原因,该setInterval()方法只能工作一次,我无法让它updateTime() …
javascript model-view-controller controller setinterval angularjs
我正在尝试制作最简单的图像幻灯片,它从div向左滚动图像.
我的问题是setInterval函数只运行一次,我正在努力解决为什么或如何修复.
提前谢谢了.我正在调用setInterval函数jQuery document.ready(函数..
<div class="highlight_Block" id="FeaturesList_block">
<div id="img_wrapper_05">
<ul id="FeaturesList_Ul">
<li id="DEMO1_000001" class="FeaturesList_li">
<img src="http://www.hostpaperz.com/wp-content/uploads/2013/06/abstract-color-349935.jpg" height="214" width="321">
</li>
<li id="DEMO1_000002" class="FeaturesList_li">
<img src="http://www.hostpaperz.com/wp-content/uploads/2013/06/Abstract-06-HD-wallpaper.jpg" width="321">
</li>
<li id="DEMO1_000003" class="FeaturesList_li">
<img src="http://www.hostpaperz.com/wp-content/uploads/2013/06/abstract-wallpapers-wallpaper-array-wallwuzz-hd-wallpaper-2830.jpg" height="214" width="321">
</li>
</ul>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
setInterval(function () {
var xyPosition_05 = $("#img_wrapper_05").position();
var next_X_Position = xyPosition_05.left + 321;
next_X_Position = '-' + next_X_Position + 'px'
$("#img_wrapper_05").animate({ left: next_X_Position }, 1000);
},5000);
Run Code Online (Sandbox Code Playgroud)
CSS:
.highlight_Block {
float:left;
width:321px;
height:300px;
margin-left:15px;
margin-top:15px;
background-color:aliceblue;
}
#FeaturesList_Ul {
list-style-type:none;
margin:0px;
padding:0px;
}
.FeaturesList_li{ …Run Code Online (Sandbox Code Playgroud) $(document).ready(function(){
setInterval(test(), 1000);
function test(){ alert('hi'); }
});
Run Code Online (Sandbox Code Playgroud)
为什么上面的代码test()只是在文档就绪而不是每一秒触发?Jsfiddle演示:这里.
我正在使用JQWidgets来创建饼图.虽然这一切都很好,花花公子,像一个魅力.然而,我想要做的是每x秒更新一次数据.使用jQuery,这是我到目前为止的代码:
function loadChart(id,name){
//chart loads here
var speed = 5000,
t = setInterval(reloadData,speed);
function reloadData() {
source.url = 'data.php?id='+id;
var dataAdapter = new $.jqx.dataAdapter(source);
$('#pie').jqxChart({ source: dataAdapter });
console.log('reloading pie...'+globalPieId);
speed = 5000;
clearInterval(t);
t = setInterval(reloadData, speed);
}
}
Run Code Online (Sandbox Code Playgroud)
我的问题是,如果调用了loadChart函数,则会创建另一个setInterval实例,并且在三到四次之后,图表将处于常量刷新状态.如何优化我的setInterval调用,以便只调用一个实例?
提前致谢.
我试图在每秒后打印一个警告或只是一条消息,比如"1秒钟过去了".有没有可能意识到这一点?
我用tic toc和循环尝试了它,但它还不够.此外,我从来没有得到一秒钟.是否有自动打印每个X ms的命令?有任何想法吗?
提前致谢.
我目前正在我的网页上使用此代码:
<?php
$url = "https://www.toontownrewritten.com/api/invasions";
$data = json_decode(file_get_contents($url));
if (!empty($data->invasions)) {
echo "<h1 style='text-align:center;margin:auto;padding:2px;font-size:16px;font-weight:bold;text-decoration:underline;padding:2px;'>Invasion Tracker</h1>";
$i = 0;
foreach($data->invasions as $title => $inv) {
print "<h3 style='text-align:center;margin:auto;'><b>District:</b> {$title}
</h3><br style='font-size:1px;'><h3 style='text-align:center;margin:auto;'><b>Cog:</b> {$inv->type}
</h3><br style='font-size:1px;'><h3 style='text-align:center;margin:auto;'><b>Progress:</b> {$inv->progress}
</h3>";
if (count(($data->invasions) > 1)) {
if (end($data->invasions) !== $inv) {
print "<hr>";
} else {
print "<br style='font-size:2px;'>";
}
}
}
} else {
echo "<h1 style='text-align:center;margin:auto;padding:2px;color:darkred;font-weight:bold;'>No invasions!</span>";
}
?>
Run Code Online (Sandbox Code Playgroud)
我希望通过AJAX每10秒刷新一次.但是,我一直在读你需要创建一个函数,但我不确定我是如何使用API的呢?每10秒,该API正在更新,这就是为什么我希望每10秒用AJAX更新一次.目前,我有它,所以用户必须手动刷新.任何帮助表示赞赏!
我有2个值
var maxValues;
var incrementValues;
Run Code Online (Sandbox Code Playgroud)
我有一个功能.
runFunction();
Run Code Online (Sandbox Code Playgroud)
值基于ajax成功而增加.
如何检查maxValues是否等于incrementValues,一旦它们相等,那么运行runFunction().
我正在使用角度5,并且有一个mat-progress-bar。我还有一个2 * 60的计时器,表示2分钟。我想每秒减少进度栏的值,两分钟后,栏的值变为0!我该怎么做?
javascript setinterval progress-bar angular-material angular5
我有这段代码:
class CombatLog {
constructor(){
this.idMsg = 0;
this.timerInterval;
}
startTimer(){
this.timerInterval = setInterval(this.combatStartLog, 2000);
$('#combatLog').empty();
}
combatStartLog(){
console.log(this.idMsg);
switch (this.idMsg){
case 3:
clearInterval(this.timerInterval);
$('#combatLog').empty();
break;
case 2:
$('<p>', {
class: 'combatText',
id: `${this.idMsg}`
}).appendTo('#combatLog');
$(`#${this.idMsg}`).append(`FIGHT!`);
this.idMsg = 3;
break;
case 1:
$('<p>', {
class: 'combatText',
id: `${this.idMsg}`
}).appendTo('#combatLog');
$(`#${this.idMsg}`).append(`Prepare your potions...`);
this.idMsg = 2;
break;
case 0:
$('<p>', {
class: 'combatText',
id: `${this.idMsg}`
}).appendTo('#combatLog');
$(`#${this.idMsg}`).append(`Unsheathe your weapons...`);
this.idMsg = 1;
break;
default:
this.idMsg = 0;
}
}
Run Code Online (Sandbox Code Playgroud)
所需的行为将是:
setinterval ×10
javascript ×8
jquery ×5
ajax ×2
angular5 ×1
angularjs ×1
carousel ×1
constructor ×1
controller ×1
hover ×1
matlab ×1
php ×1
progress-bar ×1
timer ×1