本文目錄一覽:
請問誰有右側漂浮的代碼,是JS代碼
我有 但是是左右2邊的 你直接複製 然後放在JS文件里 lastScrollY = 0; function heartBeat(){ var diffY; if (document.documentElement document.documentElement.scrollTop) diffY = document.documentElement.scrollTop; else if (document.body) diffY = document.body.scrollTop else {/*Netscape stuff*/} //alert(diffY); percent=.1*(diffY-lastScrollY); if(percent0)percent=Math.ceil(percent); else percent=Math.floor(percent); document.getElementById(“leftDiv”).style.top = parseInt(document.getElementById(“leftDiv”).style.top)+percent+”px”; document.getElementById(“rightDiv”).style.top = parseInt(document.getElementById(“rightDiv”).style.top)+percent+”px”; lastScrollY=lastScrollY+percent; //alert(lastScrollY); } //下面這段刪除後,對聯將不跟隨屏幕而移動。 window.setInterval(“heartBeat()”,1); //– //關閉按鈕 function close_left1(){ // left1.style.visibility=’hidden’; left1.style.display=’none’; leftDiv.style.display=’none’; } function close_right1(){ //right1.style.visibility=’hidden’; right1.style.display=’none’; rightDiv.style.display=’none’; } //顯示樣式 document.writeln(“style type=\”text\/css\””); document.writeln(“#leftDiv,#rightDiv{width:100px;height:100px;background-color:#fff;position:absolute;}”); document.writeln(“.itemFloat{width:100px;height:auto;line-height:5px}”); document.writeln(“\/style”); //以下為主要內容 document.writeln(“div id=\”leftDiv\” style=\”top:40px;left:5px\””); //——左側各塊開始 //—L1 document.writeln(“div id=\”left1\” class=\”itemFloat\””); document.writeln(“a href=’freecalls_business.aspx’img src=images\\index_ad_3_min.jpg width=100 height=300 //a”); document.writeln(“bra href=\”javascript:close_left1();\” title=\”關閉廣告\”×\/abrbrbrbr”); document.writeln(“\/div”); //——左側各塊結束 document.writeln(“\/div”); document.writeln(“div id=\”rightDiv\” style=\”top:40px;right:5px\””); //——右側各塊結束 //—R1 document.writeln(“div id=\”right1\” class=\”itemFloat\””); document.writeln(“a href=’huodong_kaixue.html’img src=images\\index_ad_4_min.jpg width=100 height=300 //a”); document.writeln(“bra href=\”javascript:close_right1();\” title=\”關閉廣告\”×\/abrbrbrbr”); document.writeln(“\/div”); //——右側各塊結束 document.writeln(“\/div”);
記得採納啊
求一段JS廣告底部漂浮代碼
你先寫一個底部漂浮框
然後判斷屏幕的尺寸在手機端讓他顯示
求段網頁右下角漂浮的JS代碼,放廣告用的!
!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “”
html xmlns=””
head
title不會被屏蔽的網頁右下角漂浮窗口代碼/title
FCK:meta http-equiv=”content-type” content=”text/html;charset=gb2312″ /
style type=”text/css”
#msg_win{border:1px solid #A67901;background:#EAEAEA;width:300px;position:absolute;right:0;font-size:12px;font-family:Arial;margin:0px;display:none;overflow:hidden;z-index:99;}
#msg_win .icos{position:absolute;top:2px;*top:0px;right:2px;z-index:9;}
.icos a{float:left;color:#833B02;margin:1px;text-align:center;font-weight:bold;width:14px;height:22px;line-height:22px;padding:1px;text-decoration:none;font-family:webdings;}
.icos a:hover{color:#fff;}
#msg_title{background:#FECD00;border-bottom:1px solid #A67901;border-top:1px solid #FFF;border-left:1px solid #FFF;color:#000;height:25px;line-height:25px;text-indent:5px;}
#msg_content{margin:0px;width:300px;height:300px;overflow:hidden;}
/style
/head
body
p style=”height:1000px;”/p
div id=”msg_win” style=”display:block;top:490px;visibility:visible;opacity:1;”
div class=”icos”a id=”msg_min” title=”最小化” href=”javascript:void 0″ _fcksavedurl=”javascript:void 0″_/aa id=”msg_close” title=”關閉” href=”javascript:void 0″ _fcksavedurl=”javascript:void 0″×/a/div
div id=”msg_title”標題/div
div id=”msg_content”
img src=”” width=”300″ height=”300″ border=”0″/
/div
/div
script language=”javascript”
var Message={
set: function() {//最小化與恢復狀態切換
var set=this.minbtn.status == 1?[0,1,’block’,this.char[0],’最小化’]:[1,0,’none’,this.char[1],’恢復’];
this.minbtn.status=set[0];
this.win.style.borderBottomWidth=set[1];
this.content.style.display =set[2];
this.minbtn.innerHTML =set[3]
this.minbtn.title = set[4];
this.win.style.top = this.getY().top;
},
close: function() {//關閉
this.win.style.display = ‘none’;
window.onscroll = null;
},
setOpacity: function(x) {//設置透明度
var v = x = 100 ? ”: ‘Alpha(opacity=’ + x + ‘)’;
this.win.style.visibility = x=0?’hidden’:’visible’;//IE有絕對或相對定位內容不隨父透明度變化的bug
this.win.style.filter = v;
this.win.style.opacity = x / 100;
},
show: function() {//漸顯
clearInterval(this.timer2);
var me = this,fx = this.fx(0, 100, 0.1),t = 0;
this.timer2 = setInterval(function() {
t = fx();
me.setOpacity(t[0]);
if (t[1] == 0) {clearInterval(me.timer2) }
},10);
},
fx: function(a, b, c) {//緩衝計算
var cMath = Math[(a – b) 0 ? “floor”: “ceil”],c = c || 0.1;
return function() {return [a += cMath((b – a) * c), a – b]}
},
getY: function() {//計算移動坐標
var d = document,b = document.body, e = document.documentElement;
var s = Math.max(b.scrollTop, e.scrollTop);
var h = /BackCompat/i.test(document.compatMode)?b.clientHeight:e.clientHeight;
var h2 = this.win.offsetHeight;
return {foot: s + h + h2 + 2+’px’,top: s + h – h2 – 2+’px’}
},
moveTo: function(y) {//移動動畫
clearInterval(this.timer);
var me = this,a = parseInt(this.win.style.top)||0;
var fx = this.fx(a, parseInt(y));
var t = 0 ;
this.timer = setInterval(function() {
t = fx();
me.win.style.top = t[0]+’px’;
if (t[1] == 0) {
clearInterval(me.timer);
me.bind();
}
},10);
},
bind:function (){//綁定窗口滾動條與大小變化事件
var me=this,st,rt;
window.onscroll = function() {
clearTimeout(st);
clearTimeout(me.timer2);
me.setOpacity(0);
st = setTimeout(function() {
me.win.style.top = me.getY().top;
me.show();
},600);
};
window.onresize = function (){
clearTimeout(rt);
rt = setTimeout(function() {me.win.style.top = me.getY().top},100);
}
},
init: function() {//創建HTML
function $(id) {return document.getElementById(id)};
this.win=$(‘msg_win’);
var set={minbtn: ‘msg_min’,closebtn: ‘msg_close’,title: ‘msg_title’,content: ‘msg_content’};
for (var Id in set) {this[Id] = $(set[Id])};
var me = this;
this.minbtn.onclick = function() {me.set();this.blur()};
this.closebtn.onclick = function() {me.close()};
this.char=navigator.userAgent.toLowerCase().indexOf(‘firefox’)+1?[‘_’,’::’,’×’]:[‘0′,’2′,’r’];//FF不支持webdings字體
this.minbtn.innerHTML=this.char[0];
this.closebtn.innerHTML=this.char[2];
setTimeout(function() {//初始化最先位置
me.win.style.display = ‘block’;
me.win.style.top = me.getY().foot;
me.moveTo(me.getY().top);
},0);
return this;
}
};
Message.init();
/script
/body
/html
怎麼寫「返回頂部」的代碼?
你應該說明一下需要編寫的網頁語言,這樣也好寫一下。
HTML的代碼:
使用HTML的錨標記最簡單了,但是唯一的缺點就是樣式不怎麼樣,會顯示這個錨標記。
a name=”top” id=”top”/a
放置位置在body標籤之後隨便找個地方放都可以,只要靠近頂部即可。
頁面底部放置:
a href=”#top” target=”_self”返回頂部/a
使用Javascript Scroll函數返回頂部
使用Javascript Scroll函數返回頂部
scrooll函數用來控制滾動條的位置,有兩種很簡單的實現方式:
方式1:
a href=”javascript:scroll(0,0)”返回頂部/a
scroll第一個參數是水平位置,第二個參數是垂直位置,比如要想定位在垂直50像素處,改成scroll(0,50)就可以了。
方式2:
本方式是漸進式返回頂部,要好看一些,代碼如下:
function pageScroll() {
window.scrollBy(0,-10);
scrolldelay = setTimeout(‘pageScroll()’,100);
}
a href=”pageScroll();”返回頂部/a
這樣就會動態返回頂部,不過雖然返回到頂部但是代碼仍在運行,還需要在pageScroll函數加一句給停止掉。
if(document.documentElement.scrollTop==0) clearTimeout(scrolldelay);
三、使用Onload加上scroll功能實現動態返回頂部
首先在網頁BODY標籤結束之前加上:
div id=”gotop”返回頂部/div
2、再調用以下JS腳本部分:
BackTop=function(btnId){
var btn=document.getElementById(btnId);
var d=document.documentElement;
window.onscroll=set;
btn.onclick=function (){
btn.style.display=”none”;
window.onscroll=null;
this.timer=setInterval(function(){
d.scrollTop-=Math.ceil(d.scrollTop*0.1);
if(d.scrollTop==0) clearInterval(btn.timer,window.onscroll=set);
},10);
};
function set(){btn.style.display=d.scrollTop?’block’:”none”}
};
BackTop(‘gotop’);
對Z-BLOG而言,可以放到$(document).ready(function(){….函數中,也可以獨立存成一個js文件,比如gotop.js,再通過:
SCRIPT src=”/js/gotop.js” type=text/javascript/SCRIPT
來調用,當然了位置最好放在「返回頂部」標籤的下面,該調用方法已假設路徑為JS,其它位置請自行修改。
返回頂部代碼都是文字式樣的,也可以把文字更換為漂亮一點的圖標,另外還有懸浮狀的返回頂部代碼(就是頁面滾動時,返回頂部圖標也會跟著跑的那種),需要使用到層等。
原創文章,作者:ZNIV,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/134128.html