Jquery 如果左侧<;=0
下面有几个函数可以左右滑动div。它工作得很好,只是我需要在用户到达div末尾时停止。即:左箭头的移动不应超过左:0;。在此方面的任何帮助都将不胜感激Jquery 如果左侧<;=0,jquery,css,jquery-animate,Jquery,Css,Jquery Animate,下面有几个函数可以左右滑动div。它工作得很好,只是我需要在用户到达div末尾时停止。即:左箭头的移动不应超过左:0;。在此方面的任何帮助都将不胜感激 $(".left-arrow").mouseover(function(){ playanim("+=30px"); }).mouseleave(function(){ stopanim(); }); $(".right-arrow").mouseover(function(){ playanim("-=30px"); }).mo
$(".left-arrow").mouseover(function(){
playanim("+=30px");
}).mouseleave(function(){
stopanim();
});
$(".right-arrow").mouseover(function(){
playanim("-=30px");
}).mouseleave(function(){
stopanim();
});
function playanim(speed) {
// launch the anim with the desired side
$("#slides").animate({
left: speed,
}, 1000,'linear',function(){playanim(speed);});
}
function stopanim() {
// stop the animation and clear the animation queue
$("#slides").stop(true);
}
您只需要添加一个while语句,然后在while语句之前使用jquery的position方法来获取元素的位置
While(position!={left:0}) // Or something like that
{
//then move
}
您可以在这里找到position的引用您只需要添加一个while语句,然后在while语句之前使用jquery的position方法来获取元素的位置
While(position!={left:0}) // Or something like that
{
//then move
}
您可以在这里找到position的引用您只需要添加一个while语句,然后在while语句之前使用jquery的position方法来获取元素的位置
While(position!={left:0}) // Or something like that
{
//then move
}
您可以在这里找到position的引用您只需要添加一个while语句,然后在while语句之前使用jquery的position方法来获取元素的位置
While(position!={left:0}) // Or something like that
{
//then move
}
您可以在此处找到位置参考您可以使用或检查左位置 使用
位置的解决方案
:
function playanim(speed) {
var position = $("#slides").position();
//if position (or offset, if you like) is more than 0, we may move.
if ( position.left > 0 ) {
// make sure you don't accidentally go more left than 0
if( position.left < 30) {
speed = 30 - position.left;
}
// launch the animation with the desired side
$("#slides").animate({
left: speed,
}, 1000,'linear',function(){playanim(speed);});
}
}
功能播放动画(速度){
变量位置=$(“#幻灯片”).position();
//如果位置(或偏移量,如果您愿意)大于0,我们可能会移动。
如果(位置左>0){
//确保不会意外向左移动超过0
如果(位置左<30){
速度=30-位置。左侧;
}
//启动具有所需侧面的动画
$(“#幻灯片”)。设置动画({
左:速度,
},1000,'linear',function(){playanim(速度);});
}
}
您可以使用或检查左侧位置
使用位置的解决方案
:
function playanim(speed) {
var position = $("#slides").position();
//if position (or offset, if you like) is more than 0, we may move.
if ( position.left > 0 ) {
// make sure you don't accidentally go more left than 0
if( position.left < 30) {
speed = 30 - position.left;
}
// launch the animation with the desired side
$("#slides").animate({
left: speed,
}, 1000,'linear',function(){playanim(speed);});
}
}
功能播放动画(速度){
变量位置=$(“#幻灯片”).position();
//如果位置(或偏移量,如果您愿意)大于0,我们可能会移动。
如果(位置左>0){
//确保不会意外向左移动超过0
如果(位置左<30){
速度=30-位置。左侧;
}
//启动具有所需侧面的动画
$(“#幻灯片”)。设置动画({
左:速度,
},1000,'linear',function(){playanim(速度);});
}
}
您可以使用或检查左侧位置
使用位置的解决方案
:
function playanim(speed) {
var position = $("#slides").position();
//if position (or offset, if you like) is more than 0, we may move.
if ( position.left > 0 ) {
// make sure you don't accidentally go more left than 0
if( position.left < 30) {
speed = 30 - position.left;
}
// launch the animation with the desired side
$("#slides").animate({
left: speed,
}, 1000,'linear',function(){playanim(speed);});
}
}
功能播放动画(速度){
变量位置=$(“#幻灯片”).position();
//如果位置(或偏移量,如果您愿意)大于0,我们可能会移动。
如果(位置左>0){
//确保不会意外向左移动超过0
如果(位置左<30){
速度=30-位置。左侧;
}
//启动具有所需侧面的动画
$(“#幻灯片”)。设置动画({
左:速度,
},1000,'linear',function(){playanim(速度);});
}
}
您可以使用或检查左侧位置
使用位置的解决方案
:
function playanim(speed) {
var position = $("#slides").position();
//if position (or offset, if you like) is more than 0, we may move.
if ( position.left > 0 ) {
// make sure you don't accidentally go more left than 0
if( position.left < 30) {
speed = 30 - position.left;
}
// launch the animation with the desired side
$("#slides").animate({
left: speed,
}, 1000,'linear',function(){playanim(speed);});
}
}
功能播放动画(速度){
变量位置=$(“#幻灯片”).position();
//如果位置(或偏移量,如果您愿意)大于0,我们可能会移动。
如果(位置左>0){
//确保不会意外向左移动超过0
如果(位置左<30){
速度=30-位置。左侧;
}
//启动具有所需侧面的动画
$(“#幻灯片”)。设置动画({
左:速度,
},1000,'linear',function(){playanim(速度);});
}
}
位置
是一个对象。你不能在这里直接使用它。请参见下面我的答案位置是一个对象。你不能在这里直接使用它。请参见下面我的答案位置是一个对象。你不能在这里直接使用它。请参见下面我的答案位置是一个对象。你不能在这里直接使用它。见下面我的答案