자바 스크립트 클래스에 jquery 함수를 삽입 할 수 있습니까? 예를 들어 I는 다음 JS 클래스를 가지고jquery 메서드를 자바 스크립트 클래스 메서드로
function FloatingImage() {
var delay, duration;
var moveRight = function($image)
{
$image.delay(delay).animate(
{
left: $image.parent().width() - $image.width()
},
{
duration: duration,
complete: function(){ moveLeft($image) }
});
},
moveLeft = function($image){
$image.delay(delay).animate({
left: 0
}, {
duration: duration,
complete: function(){ moveRight($image) }
});
};
this.constructor = function (delay, duration) {
this.delay = delay;
this.duration = duration;
};
}
다음 지원 기능 : 다음
function rand(l,u) // lower bound and upper bound
{
return Math.floor((Math.random() * (u-l+1))+l);
}
, 그것은 호출 가정 배경 모두 2 개 이미지 2 명 div에 #imgleft 및 #imgright 거기 다음을 포함합니다 :
$(function(){
var $imageL = $('#imgleft'),
$imageR = $('#imgright');
var fi1 = new FloatingImage();
fi1.constructor(rand(400,600), rand(1500,3000));
var fi2 = new FloatingImage();
fi2.constructor(rand(400,600), rand(1500,3000));
fi1.moveRight($imageL);
fi2.moveLeft($imageR);
});
시도해 보셨습니까? 오류나 예기치 않은 동작이 있습니까? 예, JavaScript 생성자 또는 프로토 타입에 jQuery를 포함 할 수 있습니다. – apsillers
jQuery는 자바 스크립트 코드입니다. 당신은 정확한 그것을 할 수 있습니까? 뭐하고 싶어 ? 너 뭐하니? 내가 뭘 해봤 니? 어떤 오류가 발생합니까? BTW, 자바 스크립트에는 "클래스"가 없습니다 – pomeh
@pomeh 불명확합니다. 이 샘플과 같이 2 개의 이미지를 옮기고 싶습니다. http://jsfiddle.net/linuxatico/XnPjL/ 하지만 다른 코드를 재구성하여 신속하게 다른 지연과 지속 시간을 할당 할 수 있습니다. – linuxatico