PDA

View Full Version : آموزش: ساخت news ticker-typewriter به صورت پویا



aserfg
جمعه 15 مهر 1390, 17:15 عصر
در سایت های مختلف با افکتهای جالبی در بالای سایت برخورد داشته اید . مانند سایت یاهو در این آدرس (http://en.news.maktoob.com/20090001123540/Error_CCTV_captures_man_walking_through_glass_wind ow/Article.htm) بالا قسمت Top stories
روش ذیل حاصل چهار ساعت تلاش است . درسته حجم کد کمه ولی خطا زدایی اون برا من خیلی خسته کننده بود (مثل همیشه جاوا اسکریپت بد قلق شده بود شایدم علتش )
مراحل انجام کار :
1- نوشتن تابع جاوا اسکریپت
2-پر کردن آرایه های جاوا اسکریپت در کد بیهایند .
تابع جاوا اسکریپت :
var arraycount = 0;
var count =0;
var mytext;
var names=new Array();
var href=new Array();
function typetext() {


document.getElementById('tickerspan').innerHTML += mytext.charAt(count);
if (count < mytext.length - 1) { count++; setTimeout('typetext()', 200); }
else {
doempty();
}
}
function doempty() {

document.getElementById('tickerspan').innerHTML = "";
mytext = " ";

if (names.length > 0 ) {

if (arraycount < names.length ) {
mytext = names[arraycount];
document.getElementById('linknews').setAttribute(' href', href[arraycount]);
arraycount += 1;

}
else {
arraycount = 0;

}


}


count = 0;
setTimeout('typetext()', 3000);

}

این هم کد بیهایند :

protected void Page_Load(object sender, EventArgs e)
{
string[] mylinks = { "http://yahoo.com", "http://google.com", "http://dfkj.com" };
string[] myarray = { "سایت یاهو افتتاح شد", "گوگل مثل همیشه", "سایت الکی.." };
for (int i = 0; i < myarray.Length; i++)
{
string href = string.Format("'{0}'", mylinks[i]);
string value = string.Format("'{0}'", myarray[i]);
Page.ClientScript.RegisterArrayDeclaration("names", value);
Page.ClientScript.RegisterArrayDeclaration("href", href);
}

}

سورس آموزش رو تو سایتم گذاشتم دانلود کنید
http://persianarticle.org/article.aspx?id=109&idauthore=1