第一種

創(chuàng)新互聯(lián)公司主營(yíng)梁子湖網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營(yíng)網(wǎng)站建設(shè)方案,成都app軟件開(kāi)發(fā)公司,梁子湖h5微信小程序開(kāi)發(fā)搭建,梁子湖網(wǎng)站營(yíng)銷(xiāo)推廣歡迎梁子湖等地區(qū)企業(yè)咨詢
/**
*?JavaScript腳本實(shí)現(xiàn)回到頁(yè)面頂部示例
*?@param?acceleration?速度
*?@param?stime?時(shí)間間隔?(毫秒)
**/
function?gotoTop(acceleration,stime)?{
acceleration?=?acceleration?||?0.1;
stime?=?stime?||?10;
var?x1?=?0;
var?y1?=?0;
var?x2?=?0;
var?y2?=?0;
var?x3?=?0;
var?y3?=?0;?
if?(document.documentElement)?{
x1?=?document.documentElement.scrollLeft?||?0;
y1?=?document.documentElement.scrollTop?||?0;
}
if?(document.body)?{
x2?=?document.body.scrollLeft?||?0;
y2?=?document.body.scrollTop?||?0;
}
var?x3?=?window.scrollX?||?0;
var?y3?=?window.scrollY?||?0;
//?滾動(dòng)條到頁(yè)面頂部的水平距離
var?x?=?Math.max(x1,?Math.max(x2,?x3));
//?滾動(dòng)條到頁(yè)面頂部的垂直距離
var?y?=?Math.max(y1,?Math.max(y2,?y3));
//?滾動(dòng)距離?=?目前距離?/?速度,?因?yàn)榫嚯x原來(lái)越小,?速度是大于?1?的數(shù),?所以滾動(dòng)距離會(huì)越來(lái)越小
var?speeding?=?1?+?acceleration;
window.scrollTo(Math.floor(x?/?speeding),?Math.floor(y?/?speeding));
//?如果距離不為零,?繼續(xù)調(diào)用函數(shù)
if(x?gt;?0?||?y?gt;?0)?{
var?run?=?"gotoTop("?+?acceleration?+?",?"?+?stime?+?")";
window.setTimeout(run,?stime);
}
}
第二種
function?pageScroll()?{??
window.scrollBy(0,-10);??
scrolldelay?=?setTimeout('pageScroll()',100);??
}??
/*
scrollBy()?方法可把內(nèi)容滾動(dòng)指定的像素?cái)?shù)。
語(yǔ)法
scrollBy(xnum,ynum)
參數(shù)描述
xnum????必需。把文檔向右滾動(dòng)的像素?cái)?shù)。????
ynum????必需。把文檔向下滾動(dòng)的像素?cái)?shù)。????
8?
1、css文件夾和js文件夾里面的css和js文件引入你的頁(yè)面里面。
2、把index.html里面的HTML代碼部分復(fù)制到你的頁(yè)面。然后預(yù)覽效果。
3、然后把具體的參數(shù)調(diào)一下,比如下載了個(gè)焦點(diǎn)圖,可以把寬度和高度之類(lèi)的調(diào)成你所需要的。
如果還不是很明白,可以加js代碼交流群:304683253
!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""
html xmlns=""
head
meta http-equiv="Content-Type" content="text/html; charset=gb2312"
title網(wǎng)頁(yè)特效 首頁(yè)圖片切換/title
style type="text/css"
/* Reset style */
* { margin:0; padding:0; word-break:break-all; }
body {
background:#fff;
color:#000000;
font:12px/1.6em Helvetica, Arial, sans-serif;
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
h1, h2, h3, h4, h5, h6 { font-size:1em; }
a { color:#0287CA; text-decoration:none; }
a:hover { text-decoration:underline; }
ul, li { list-style:none; }
fieldset, img { border:none; }
legend { display:none; }
em, strong, cite, th { font-style:normal; font-weight:normal; }
input, textarea, select, button { font:12px Helvetica, Arial, sans-serif; }
table { border-collapse:collapse; }
html { overflow:-moz-scrollbars-vertical; } /*Always show Firefox scrollbar*/
/* iFocus style */
#ifocus { width:650px; height:245px; margin:0px; border:1px solid #DEDEDE; background:#F8F8F8; }
#ifocus_pic { display:inline; position:relative; float:left; width:540px; height:225px; overflow:hidden; margin:10px 0 0 10px; }
#ifocus_piclist { position:absolute; }
#ifocus_piclist li { width:550px; height:225px; overflow:hidden; }
#ifocus_piclist img { width:550px; height:225px; }
#ifocus_btn { display:inline; float:right; width:91px; margin:9px 9px 0 0; }
#ifocus_btn li { width:91px; height:57px; cursor:pointer; opacity:0.5; -moz-opacity:0.5; filter:alpha(opacity=50); }
#ifocus_btn img { width:75px; height:45px; margin:7px 0 0 11px; }
#ifocus_btn .current { background: url(img/ifocus_btn_bg.gif) no-repeat; opacity:1; -moz-opacity:1; filter:alpha(opacity=100); }
#ifocus_opdiv { position:absolute; left:0; bottom:0; width:545px; height:35px; background:#000; opacity:0.5; -moz-opacity:0.5; filter:alpha(opacity=50); }
#ifocus_tx { position:absolute; left:8px; bottom:8px; color:#FFF; }
#ifocus_tx .normal { display:none; }
/style
script type="text/javascript"
function $(id) { return document.getElementById(id); }
function addLoadEvent(func){
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function(){
oldonload();
func();
}
}
}
function moveElement(elementID,final_x,final_y,interval) {
if (!document.getElementById) return false;
if (!document.getElementById(elementID)) return false;
var elem = document.getElementById(elementID);
if (elem.movement) {
clearTimeout(elem.movement);
}
if (!elem.style.left) {
elem.style.left = "0px";
}
if (!elem.style.top) {
elem.style.top = "0px";
}
var xpos = parseInt(elem.style.left);
var ypos = parseInt(elem.style.top);
if (xpos == final_x ypos == final_y) {
return true;
}
if (xpos final_x) {
var dist = Math.ceil((final_x - xpos)/10);
xpos = xpos + dist;
}
if (xpos final_x) {
var dist = Math.ceil((xpos - final_x)/10);
xpos = xpos - dist;
}
if (ypos final_y) {
var dist = Math.ceil((final_y - ypos)/10);
ypos = ypos + dist;
}
if (ypos final_y) {
var dist = Math.ceil((ypos - final_y)/10);
ypos = ypos - dist;
}
elem.style.left = xpos + "px";
elem.style.top = ypos + "px";
var repeat = "moveElement('"+elementID+"',"+final_x+","+final_y+","+interval+")";
elem.movement = setTimeout(repeat,interval);
}
function classNormal(iFocusBtnID,iFocusTxID){
var iFocusBtns= $(iFocusBtnID).getElementsByTagName('li');
var iFocusTxs = $(iFocusTxID).getElementsByTagName('li');
for(var i=0; iiFocusBtns.length; i++) {
iFocusBtns[i].className='normal';
iFocusTxs[i].className='normal';
}
}
function classCurrent(iFocusBtnID,iFocusTxID,n){
var iFocusBtns= $(iFocusBtnID).getElementsByTagName('li');
var iFocusTxs = $(iFocusTxID).getElementsByTagName('li');
iFocusBtns[n].className='current';
iFocusTxs[n].className='current';
}
function iFocusChange() {
if(!$('ifocus')) return false;
$('ifocus').onmouseover = function(){atuokey = true};
$('ifocus').onmouseout = function(){atuokey = false};
var iFocusBtns = $('ifocus_btn').getElementsByTagName('li');
var listLength = iFocusBtns.length;
iFocusBtns[0].onmouseover = function() {
moveElement('ifocus_piclist',0,0,5);
classNormal('ifocus_btn','ifocus_tx');
classCurrent('ifocus_btn','ifocus_tx',0);
}
if (listLength=2) {
iFocusBtns[1].onmouseover = function() {
moveElement('ifocus_piclist',0,-225,5);
classNormal('ifocus_btn','ifocus_tx');
classCurrent('ifocus_btn','ifocus_tx',1);
}
}
if (listLength=3) {
iFocusBtns[2].onmouseover = function() {
moveElement('ifocus_piclist',0,-450,5);
classNormal('ifocus_btn','ifocus_tx');
classCurrent('ifocus_btn','ifocus_tx',2);
}
}
if (listLength=4) {
iFocusBtns[3].onmouseover = function() {
moveElement('ifocus_piclist',0,-675,5);
classNormal('ifocus_btn','ifocus_tx');
classCurrent('ifocus_btn','ifocus_tx',3);
}
}
}
setInterval('autoiFocus()',3500);
var atuokey = false;
function autoiFocus() {
if(!$('ifocus')) return false;
if(atuokey) return false;
var focusBtnList = $('ifocus_btn').getElementsByTagName('li');
var listLength = focusBtnList.length;
for(var i=0; ilistLength; i++) {
if (focusBtnList[i].className == 'current') var currentNum = i;
}
if (currentNum==0listLength!=1 ){
moveElement('ifocus_piclist',0,-225,5);
classNormal('ifocus_btn','ifocus_tx');
classCurrent('ifocus_btn','ifocus_tx',1);
}
if (currentNum==1listLength!=2 ){
moveElement('ifocus_piclist',0,-450,5);
classNormal('ifocus_btn','ifocus_tx');
classCurrent('ifocus_btn','ifocus_tx',2);
}
if (currentNum==2listLength!=3 ){
moveElement('ifocus_piclist',0,-675,5);
classNormal('ifocus_btn','ifocus_tx');
classCurrent('ifocus_btn','ifocus_tx',3);
}
if (currentNum==3 ){
moveElement('ifocus_piclist',0,0,5);
classNormal('ifocus_btn','ifocus_tx');
classCurrent('ifocus_btn','ifocus_tx',0);
}
if (currentNum==1listLength==2 ){
moveElement('ifocus_piclist',0,0,5);
classNormal('ifocus_btn','ifocus_tx');
classCurrent('ifocus_btn','ifocus_tx',0);
}
if (currentNum==2listLength==3 ){
moveElement('ifocus_piclist',0,0,5);
classNormal('ifocus_btn','ifocus_tx');
classCurrent('ifocus_btn','ifocus_tx',0);
}
}
addLoadEvent(iFocusChange);
/script
/head
body
br /
div align="center"
div id="ifocus"
div id="ifocus_pic"
div id="ifocus_piclist" style="left:0; top:0;"
ul
lia href="#" target="_blank"img src="/edu/img/js/200909/1.jpg" alt="武林三國(guó)" border="0" //a/li
lia href="#" target="_blank"img src="/edu/img/js/200909/2.jpg" alt="武林英雄" border="0" //a/li
lia href="#" target="_blank"img src="/edu/img/js/200909/3.jpg" alt="商業(yè)大亨" border="0" //a/li
lia href="#" target="_blank"img src="/edu/img/js/200909/4.jpg" alt="帝國(guó)遠(yuǎn)征" border="0" //a/li
/ul
/div
div id="ifocus_opdiv"/div
div id="ifocus_tx"
ul
li class="current"2008年度排名第一的網(wǎng)頁(yè)游戲/li
li class="normal"2009年最新的網(wǎng)頁(yè)游戲 /li
li class="normal"商業(yè)大亨,挑戰(zhàn)億萬(wàn)富翁/li
li class="normal"一款2009年不得不玩的帝國(guó)遠(yuǎn)征/li
/ul
/div
/div
div id="ifocus_btn"
ul
li class="current"img src="/edu/img/js/200909/s1.jpg" alt="" //li
li class="normal"img src="/edu/img/js/200909/s2.jpg" alt="" //li
li class="normal"img src="/edu/img/js/200909/s3.jpg" alt="" //li
li class="normal"img src="/edu/img/js/200909/s4.jpg" alt="" //li
/ul
/div
/div
/div
/body
/html
自己改圖片鏈接和大小~~
script language="javascript" type="text/javascript"
//圖片滾動(dòng)展示 Start
var counts = 4;
//大圖//
img1 = new Image();
img1.src = 'images/1.jpg';
img2 = new Image();
img2.src = 'images/2.jpg';
img3 = new Image();
img3.src = 'images/3.jpg';
img4 = new Image();
img4.src = 'images/4.jpg';
var smallImg = new Array();
//小圖
smallImg[0] = 'images/index_adb1.gif';
smallImg[1] = 'images/index_adb2.gif';
smallImg[2] = 'images/index_adb3.gif';
smallImg[3] = 'images/index_adb4.gif';
//鏈接地址
url1 = new Image();
url1.src = ' ';
url2 = new Image();
url2.src = ' ';
url3 = new Image();
url3.src = ' ';
url4=new Image();
url4.src=' '
//alt值
alt1 = new Image();
alt1.alt = '';
alt2 = new Image();
alt2.alt = '';
alt3 = new Image();
alt3.alt = ' ';
alt4 = new Image();
alt4.alt='';
////歡迎來(lái)到標(biāo)準(zhǔn)之路.
var nn = 1;
var key = 0;
function change_img() {
if (key == 0) {
key = 1;
} else if (document.all) {
document.getElementById("pic").filters[0].Apply();
document.getElementById("pic").filters[0].Play(duration = 2);
}
eval('document.getElementById("pic").src=img' + nn + '.src');
eval('document.getElementById("url").href=url' + nn + '.src');
eval('document.getElementById("pic").alt=alt' + nn + '.alt');
if (nn == 1) {
document.getElementById("url").target = "_blank";
document.getElementById("url").style.cursor = "pointer";
} else {
document.getElementById("url").target = "_blank"
document.getElementById("url").style.cursor = "pointer"
}
for ( var i = 1; i = counts; i++) {
document.getElementById("xxjdjj" + i).className = 'axx';
}
document.getElementById("xxjdjj" + nn).className = 'bxx';
nn++;
if (nn counts) {
nn = 1;
}
tt = setTimeout('change_img()', 7000);
}
function changeimg(n) {
nn = n;
window.clearInterval(tt);
change_img();
}
function imageshow() {
document.write('div class="picshow_main"');
document.write('diva id="url"img id="pic" class="imgbig" //a/div');
document.write('div class="picshow_change"');
for ( var i = 0; i counts; i++) {
document.write('a href="javascript:changeimg(' + (i + 1)
+ ');" id="xxjdjj' + (i + 1)
+ '" class="axx" target="_self"img src="' + smallImg[i]
+ '"/a');
}
document.write('/div/div');
change_img();
}
//圖片滾動(dòng)展示 End
/script
script language="javascript" type="text/javascript"
imageshow();
/script
這種東西網(wǎng)上很多,想懶人圖庫(kù),腳本之家等什么的,javascript實(shí)現(xiàn)挺好的,調(diào)下兼容性就可以了。你看這個(gè)鏈接合適嗎
很順暢的1號(hào):
傳送門(mén):
漂亮的2號(hào):
傳送門(mén):
特別帥的3號(hào):
傳送門(mén):
本文標(biāo)題:關(guān)于javascript懶人的信息
文章起源:http://chinadenli.net/article15/dsgcggi.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App開(kāi)發(fā)、網(wǎng)站建設(shè)、ChatGPT、外貿(mào)網(wǎng)站建設(shè)、企業(yè)網(wǎng)站制作、網(wǎng)站改版
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)