|
(function (jQuery) {
/**
* DATE:2012/01/22
*
* @projectDescription imitate the meager rolling effect
*
* @author Joe nikejaycn#gmail.com
* @version v0.1
*/
JQuery.fn.iscroll = function (params) {
Options = {
SHOWTIME:500,//Show time
movetime:3000,//Mobile time
Charelement: "Li",//child node
Ajaxtrunon:false,//whether to open the Ajax request, timed to get the data
ajaxtime:30000,//Send an AJAX request time, default is 30 seconds to get data
Ajaxurl: "",//ajax Data Request path
Setajaxhtml:function (data) {//DataSource output settings
Data is an AJAX return
Format the output here
}
};
Jquery.extend (options, params);
Save current object
var _this = this,
Isie =!! Window. ActiveXObject,
IsIE6 = Isie&&!window. XMLHttpRequest,
Jsondata = False,
Jsoncount =-1;
The mouse is set to the name value "hovered"
function Sethover () {
_this.hover (function () {
_this.attr ("name", "hovered");
},function () {
_this.removeattr ("name");
});
}sethover ();
function Animatehandler () {
if (Options.ajaxtrunon) {
Processing request data
Handlerjson ();
}
var height = _this.find (". Itemt:last"). Height ();
_this.find (". Itemt:last"). CSS ({"opacity": 0, "height": 0});
_this.find (". Itemt:first"). Before (_this.find (". Itemt:last"));
_this.find (". Itemt:first"). Animate ({"Height": height},options.) ShowTime);
_this.find (". Itemt:first"). Animate ({"Opacity": "1"},options. ShowTime);
}
function Setmove () {
if (_this.attr ("name")!= "hovered") {
Animatehandler ();
}
}
Set timed scrolling
SetInterval (function () {
jsoncount++;
Setmove ();
},options.movetime);
Timed query data once
if (Options.ajaxtrunon) {
SetInterval (function () {
Getnewslist ();
},options.ajaxtime);
}
Ajax request
function Getnewslist () {
$.ajax ({
URL:OPTIONS.AJAXURL,
Datatypes: "JSON",
Success:function (JSON) {
Jsoncount =-1;
Jsondata = JSON;
}
})
}
Processing request-back JSON
function Handlerjson () {
if (jsondata) {
_jsondata = eval ("+jsondata +"));
var _length = _jsondata.length;
if (Jsoncount < _length) {
Working with the appropriate functions
_this.find (". Itemt:last"). CSS ("height", "Auto");//Clear height
_this.find (". Itemt:last"). HTML (options.setajaxhtml (_jsondata[jsoncount));
}
}
}
}
}) (JQuery); |