使用jQuery, CSS, JSON 和ASP.NET打造一个新闻轮换控件
2010-01-08 00:00:00 来源:WEB开发网<script type="text/javascript">
new TopNews('#Container', 7,true,6000);
</script>
TopNews 函数参数描述:
代码
TopNews function parameters:
parameter 1(objRoot): newsRotator control container (a jquery selector),
the control uses this parameter as a prefix (root object) of every
jquery selector inside the control.this prefix helps to have multiple instance
of control in the page without any worry of jquery selection conflict.
parameter 2(newsCountPerPage): number of news items in a page.
parameter 3(viewSubtitle): a boolean value makes subtitle section
of the control enable or disable. the rest of the news titles shows
in the subtitle section randomly at the bottom of the current page.
parameter 4(Interval): news rotation (slideshow) interval in millisecond.
4、 需要一个服务端来收集新闻。 然后将新闻转化成JSON格式,将它发送到客户端。
在客户端,我们使用Jquery发送一个Ajax请求去调用服务端的方法。
代码
//call ASP.NET page method asynchronous (send and recives data in JSON format)
PageMethod: function(fn, paramArray, successFn, errorFn) {
var pagePath = window.location.pathname;
var that = this;
//Call the page method
$.ajax({
type: "POST",
url: pagePath + "?Callback=" + fn,
contentType: "application/json; charset=utf-8",
data: paramArray,
dataType: "json",
//that is a reference to the object calling this callback method
success: function(res) { successFn(res, that) },
error: errorFn
});
}
更多精彩
赞助商链接