正在修复if语句以停止移动
Fixing if statement to stop movement
我试图实现的目标
racer偏移是为了让用户可以设置一个图像可以在px中移动多远。偏移量管理它偏移了多远。Speed-racer告诉图像在滚动过程中移动的速度。我的问题是它不会停止。我可以提供一把小提琴,但让我们先试试,看看没有它是否很容易修复。谢谢。
HTML
<img class="images" racer-offset="250" speed-racer="3" src="http://assets/img/fwman/FeeneyMan_bike.png" loc="576" style="left: 540px;" offsetted="924">
Javascript
$(window).scroll(function(){
$('.images').each(function(){
if($('this').attr('racer-offset') < $(this).attr('offsetted')){
}
else {
var speedR = $(this).attr('speed-racer');
$('.images').css({left : "-="+speedR});
$('.images').attr('offsetted', $(this).position().left);
}
});
});
$('.images').each(function(){
$(this).attr('loc', $(this).position().left);
});
新版本
$(window).scroll(function(){
if(lastLeftLocation > $(document).scrollLeft()) {
$('.images').each(function(){
if($(this).position().left >= $(this).attr('loc')){
console.log("0 == stopped");
}
else {
speedR = $(this).attr('speed-racer');
$(this).css({left : "+="+speedR});
$(this).attr('racer-offset') + speedR;
$(this).attr('racer-offset', $(this).attr('speed-racer') + $(this).attr('racer-offset'));
}
});
}
else {
$('.images').each(function(){
if($(this).attr('racer-offset') <= 0){
console.log("0 == stopped");
}
else {
speedR = $(this).attr('speed-racer');
$(this).css({left : "-="+speedR});
$(this).attr('racer-offset', $(this).attr('racer-offset') - speedR);
}
});
}
});
唯一需要修复的是,我需要速度赛车手在if部分添加赛车手偏移。
$(this).attr('racer-offset', $(this).attr('speed-racer') + $(this).attr('racer-offset'));
由于某些原因,您的引号中有this
。。
$(this)和$[(' 应该是this
')if($('this').
if($(this).
代码的这一部分不应该是:吗
var speedR = $(this).attr('speed-racer');
//$('.images').css({left : "-="+speedR});
$(this).css({left: "-="+speedR});
//$('.images').attr('offsetted', $(this).position().left);
$(this).attr('offsetted', $(this).position().left);
}
注意:不过没有测试。
相关文章:
- 可以't让我的if语句处理js中的html表单输入
- Canvas Html5绘图应用程序,移动画布会导致重大问题
- 如何在ReactJS JSX中执行嵌套的if-else语句
- 正在SharePoint 2013母版页中添加JQuery移动文件
- 如何在android中使用phonegap将文件从一个文件夹移动/复制到另一个文件夹
- 如何使用phaser使html5游戏在移动设备浏览器上运行
- FabricJs-限制主对象内添加对象的移动区域
- 如何从画布上的某个移动事件中获取X和Y
- 触摸移动时切换到新元素
- 每当您在选择器内移动鼠标时,悬停功能就会重复
- 停止jQuery UI滑块移动超过给定值
- 自动修复”;语句前缺少分号“;
- 谷歌地图API v3不适用于移动浏览器或PhoneGap
- 如何将chrome扩展功能移植到移动设备(特别是jquery和trello)
- JQuery移动动态分区页面
- 如何在 API 调用后和 if 语句中启用提交按钮
- 正在修复if语句以停止移动
- 移动设备if语句
- 如何在if语句中检查鼠标移动事件
- 如何在if else语句中禁用JQuery移动侧滑动