本文目錄一覽:
- 1、js如何實現新聞輪播
- 2、我想要一種新聞滾動的效果,用js實現的
- 3、js循環倒計時代碼 每5秒循環倒計時到0 再從5秒開始 到0之後刷新頁面 類似網易的滾動新聞
- 4、PHP,想實現滾動新聞效果。
- 5、求幫忙改一段簡單的網頁代碼!
js如何實現新聞輪播
加入有5張圖片,第一張css 樣式是display:block 那其餘4張圖片就是display:none對吧,然後js獲取li元素下標(一般都是li哈),利用定時任務,比如說每隔5秒就換圖片,那就是當前下標的li 樣式是display:block,其他都是display:none,就這樣循環
我想要一種新聞滾動的效果,用js實現的
可以上斑馬谷看看,圖片輪顯和網頁圖片特效,可以調整大小更改文字
js循環倒計時代碼 每5秒循環倒計時到0 再從5秒開始 到0之後刷新頁面 類似網易的滾動新聞
html
head
title JS時間循環/title
script type=”text/javascript”
window.onload = function(){
showTime(1);
}
var seconds = 5;
function showTime(time)
{
document.getElementById(“time_div”).innerHTML = seconds;
if(seconds = 0)
{
seconds–;
}
else{
seconds = 5;
window.location.reload();
}
setTimeout(“showTime()”,1000);
}
/script
/head
body
div id=”time_div”/div
/body
/html
PHP,想實現滾動新聞效果。
滾動可以用html代碼marquee/marquee實現。
可點擊新聞用a href=””/a,要在新窗口打開的話targer參數要用blank,
至於新聞在資料庫中,那資料庫中應該有id,標題,日期,內容等欄位吧。
讀取資料庫,顯示標題,新聞內容要重新寫一個頁面,把id作為參數傳遞過去,就很輕鬆了。示例下:
marqueea href=”新聞頁面連接.php?id=?=$id?” target=”blank”?=$biaoti?/a/marquee
要顯示多條的話可以用循環。思路這樣肯定沒錯。具體代碼要你自己完成了。
求幫忙改一段簡單的網頁代碼!
SCRIPT language=JAVAscript
// —— 定義全局變數
var theNewsNum;
var theAddNum;
var totalNum;
var CurrentPosion=0;
var theCurrentNews;
var theCurrentLength;
var theNewsText;
var theTargetLink;
var theCharacterTimeout;
var theNewsTimeout;
var theBrowserVersion;
var theWidgetOne;
var theWidgetTwo;
var theSpaceFiller;
var theLeadString;
var theNewsState;
function startTicker(){
// —— 設置初始數值
theCharacterTimeout = 50;//字元間隔時間
theNewsTimeout = 2000;//新聞間隔時間
theWidgetOne = “_”;//新聞前面下標符1
theWidgetTwo = “-“;//新聞前面下標符
theNewsState = 1;
theNewsNum = document.getElementById(“incoming”).children.AllNews.children.length;//新聞總條數
theAddNum = document.getElementById(“incoming”).children.AddNews.children.length;//補充條數
totalNum =theNewsNum+theAddNum;
theCurrentNews = 0;
theCurrentLength = 0;
theLeadString = ” “;
theSpaceFiller = ” “;
runTheTicker();
}
// — 基礎函數
function runTheTicker(){
if(theNewsState == 1){
if(CurrentPosiontheNewsNum){
setupNextNews();
}
else{
setupAddNews();
}
CurrentPosion++;
if(CurrentPosion=totalNum||CurrentPosion=1){
CurrentPosion=0;//最多條數不超過num_gun條
}
}
if(theCurrentLength != theNewsText.length){
drawNews();
}
else{
closeOutNews();
}
}
// — 跳轉下一條新聞
function setupNextNews(){
theNewsState = 0;
theCurrentNews = theCurrentNews % theNewsNum;
theNewsText = document.getElementById(“AllNews”).children[theCurrentNews].children.Summary.innerText;
theTargetLink = document.getElementById(“AllNews”).children[theCurrentNews].children.Summary.children[0].href;
theCurrentLength = 0;
document.all.hottext.href = theTargetLink;
theCurrentNews++;
}//歡迎來到站長特效網,我們的網址是,很好記,zz站長,js就是js特效,本站收集大量高質量js代碼,還有許多廣告代碼下載。
function setupAddNews() {
theNewsState = 0;
theCurrentNews = theCurrentNews % theAddNum;
theNewsText = document.getElementById(“AllNews”).children[theCurrentNews].children.Summary.innerText;
theTargetLink = document.getElementById(“AllNews”).children[theCurrentNews].children.Summary.children[0].href;
theCurrentLength = 0;
document.all.hottext.href = theTargetLink;
theCurrentNews++;
}
// — 滾動新聞
function drawNews(){
var myWidget;
if((theCurrentLength % 2) == 1){
myWidget = theWidgetOne;
}
else{
myWidget = theWidgetTwo;
}
document.all.hottext.innerHTML = theLeadString + theNewsText.substring(0,theCurrentLength) + myWidget + theSpaceFiller;
theCurrentLength++;
setTimeout(“runTheTicker()”, theCharacterTimeout);
}//歡迎來到站長特效網,我們的網址是,很好記,zz站長,js就是js特效,本站收集大量高質量js代碼,還有許多廣告代碼下載。
// — 結束新聞循環
function closeOutNews(){
document.all.hottext.innerHTML = theLeadString + theNewsText + theSpaceFiller;
theNewsState = 1;
setTimeout(“runTheTicker()”, theNewsTimeout);
}
window.onload=startTicker;
/SCRIPT
a href=”#ZC_BLOG_HOST#”站長特效網/a,站長必備的高質量網頁特效和廣告代碼。zzjs.net,站長js特效。hr
!–歡迎來到站長特效網,我們網站收集大量高質量js特效,提供許多廣告代碼下載,網址:,zzjs@msn.com,用.net打造靚站–
a href=”” id=”hottext”/a
div id=incoming style=”DISPLAY: none;float:left”
div id=AllNews
div id=0
div id=”Summary” style=”border:1px solid red”
a href=”” target=”_blank”fontbsky提示您:這個效果不錯吧~_~/b/font/a
a href=”” target=”_blank”font color=”red”b歡迎來到站長特效網/b/font/a /div
div id=NewsLink /div
/div
/div
div id=AddNews height=”25″/div
/div
114行和115行是顯示的內容。。。
原創文章,作者:CFAI,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/137062.html