PDA

View Full Version : استفاده از دستور while در jquery



mr.zenith
پنج شنبه 28 اردیبهشت 1391, 16:01 عصر
سلام دوستان
من می خواهم یک باکس که در صفحه دارم تا زمانی که موس روی آن نرفته یک انیمشن را انجام بده.
اگر میشه راهنمایی کنید.
while($('.cont1').hover()){
$(document).ready(function(){

$('.cont1').animate({
left:"30%",
top:"17%"
},'slow');
$('.cont1').animate({
left:"36%",
top:"23%"
},'slow');
});
}

exlord
جمعه 29 اردیبهشت 1391, 06:55 صبح
var anim_running = true;
$(document).ready(function () {

$('.cont1').hover(
function () {
anim_running = false;
$('.cont1').stop();
},
function () {
anim_running = true;
animate();
}
);
animate();

});
function animate() {
if (anim_running) {
$('.cont1').stop().animate({
left:"30%",
top:"17%"
}, 'slow', function () {
$('.cont1').stop().animate({
left:"36%",
top:"23%"
}, 'slow', function () {
animate();
});
});

}
}

mr.zenith
جمعه 29 اردیبهشت 1391, 13:30 عصر
var anim_running = true;
$(document).ready(function () {

$('.cont1').hover(
function () {
anim_running = false;
$('.cont1').stop();
},
function () {
anim_running = true;
animate();
}
);
animate();

});
function animate() {
if (anim_running) {
$('.cont1').stop().animate({
left:"30%",
top:"17%"
}, 'slow', function () {
$('.cont1').stop().animate({
left:"36%",
top:"23%"
}, 'slow', function () {
animate();
});
});

}
}
حالا اگر بخواهیم موس رفت روی باکس opacity بشه 1 و تکان نخوره ولی وقت موس رفت کنار opacity بشه 0.4 و تکان بخوره چیکار باید کرد؟

exlord
جمعه 29 اردیبهشت 1391, 15:41 عصر
function animate() {
if (anim_running) {
$('.cont1').stop().animate({
left:"30%",
top:"17%",
opacity:1
}, 'slow', function () {
$('.cont1').stop().animate({
left:"36%",
top:"23%",
opacity:0.4
}, 'slow', function () {
animate();
});
});

}
}

mr.zenith
جمعه 29 اردیبهشت 1391, 16:29 عصر
function animate() {
if (anim_running) {
$('.cont1').stop().animate({
left:"30%",
top:"17%",
opacity:1
}, 'slow', function () {
$('.cont1').stop().animate({
left:"36%",
top:"23%",
opacity:0.4
}, 'slow', function () {
animate();
});
});

}
}

من خودم این کار را انجام دادم ولی اینطوری دائما پر رنگ و کم رنگ میشه
حتی توی یک فانکشن جدا هم نوشتم ولی نشد