मेरे पास यह परीक्षण फ़ंक्शन नीचे है जो किसी तत्व को बाहर या बाहर लुप्त करने के लिए ठीक काम करता है।एनीमेशन फीका | jQuery बनाम शुद्ध जेएस | setInterval बनाम setTimeout
JQuery का उपयोग करके मुझे क्या लाभ होता है?
धन्यवाद
Effects.prototype.fade = function(direction, max_time, element)
{
var elapsed = 0;
function next() {
elapsed += 10;
if (direction === 'up')
{
element.style.opacity = elapsed/max_time;
}
else if (direction === 'down')
{
element.style.opacity = (max_time - elapsed)/max_time;
}
if (elapsed <= max_time) {
setTimeout(next, 10);
}
}
next();
};
fadein() कोर jQuery पुस्तकालय पर पर एक खोज चल रहा है मैं यहाँ एक हिट मिलती है:
jQuery.each({
slideDown: genFx("show", 1),
slideUp: genFx("hide", 1),
slideToggle: genFx("toggle", 1),
fadeIn: { opacity: "show" },
fadeOut: { opacity: "hide" },
fadeToggle: { opacity: "toggle" }
}, function(name, props) {
jQuery.fn[ name ] = function(speed, easing, callback) {
return this.animate(props, speed, easing, callback);
};
});
function (prop, speed, easing, callback) {
var optall = jQuery.speed(speed, easing, callback);
if (jQuery.isEmptyObject(prop)) {
return this.each(optall.complete, [false]);
}
prop = jQuery.extend({},
prop);
return this[optall.queue === false ? "each" : "queue"](function() {
if (optall.queue === false) {
jQuery._mark(this);
}
var opt = jQuery.extend({},
optall),
isElement = this.nodeType === 1,
hidden = isElement && jQuery(this).is(":hidden"),
name, val, p, display, e, parts, start, end, unit;
opt.animatedProperties = {};
for (p in prop) {
name = jQuery.camelCase(p);
if (p !== name) {
prop[name] = prop[p];
delete prop[p];
}
val = prop[name];
if (jQuery.isArray(val)) {
opt.animatedProperties[name] = val[1];
val = prop[name] = val[0];
} else {
opt.animatedProperties[name] = opt.specialEasing && opt.specialEasing[name] || opt.easing || "swing";
}
if (val === "hide" && hidden || val === "show" && !hidden) {
return opt.complete.call(this);
}
if (isElement && (name === "height" || name === "width")) {
opt.overflow = [this.style.overflow, this.style.overflowX, this.style.overflowY];
if (jQuery.css(this, "display") === "inline" && jQuery.css(this, "float") === "none") {
if (!jQuery.support.inlineBlockNeedsLayout) {
this.style.display = "inline-block";
} else {
display = defaultDisplay(this.nodeName);
if (display === "inline") {
this.style.display = "inline-block";
} else {
this.style.display = "inline";
this.style.zoom = 1;
}
}
}
}
}
if (opt.overflow != null) {
this.style.overflow = "hidden";
}
for (p in prop) {
e = new jQuery.fx(this, opt, p);
val = prop[p];
if (rfxtypes.test(val)) {
e[val === "toggle" ? hidden ? "show" : "hide" : val]();
} else {
parts = rfxnum.exec(val);
start = e.cur();
if (parts) {
end = parseFloat(parts[2]);
unit = parts[3] || (jQuery.cssNumber[p] ? "" : "px");
if (unit !== "px") {
jQuery.style(this, p, (end || 1) + unit);
start = (end || 1)/e.cur() * start;
jQuery.style(this, p, start + unit);
}
if (parts[1]) {
end = (parts[1] === "-=" ? -1 : 1) * end + start;
}
e.custom(start, end, unit);
} else {
e.custom(start, val, "");
}
}
}
return true;
});
}
1. आपको इसे लिखना नहीं है। 2. आपको इसे लिखना नहीं है। 3. आपको ... अच्छी तरह से नहीं है :) इस पर विचार करें कि "इसे लिखना" का अर्थ है "ब्राउज़र क्विर्क के लिए लेखांकन"। यह अच्छी तरह से चेनिंग के लिए शेष jQuery प्रभाव मॉडल में फिट बैठता है, आदि –
बस jQuery डेवलपर स्रोत डाउनलोड करें और fadeIn फ़ंक्शन निकालें। jQuery की फीडइन आपके फ़ंक्शन के समान कुछ करती है लेकिन यह समय सीमाओं को बनाए रखने की कोशिश कर लोड के तहत बेहतर प्रदर्शन करती है। साथ ही, संपूर्ण एनिमेट लाइब्रेरी काफी अच्छी तरह डिज़ाइन की गई है और सामान बस काम करता है। – Halcyon
जो मैंने पहले देखा था, jQuery फ़ंक्शन को रिकर्सिव कॉल करने के लिए टाइमर (सेटटाइमआउट) का उपयोग करता है। इस तरह, आपका यूआई संक्रमण के दौरान लॉक-अप नहीं होगा। – Joseph