JQ ajax Imitation Micro bo scrolling plug-in Jquery.iscroll

Source: Internet
Author: User
Tags json setinterval

The title, Imitation Sina Weibo home page scrolling effect written a jquery plugin.
Just began to practice writing Jquyer plug-ins, not very skilled, make up with the first.
The code is as follows:

The code is as follows Copy Code

(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);

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.