頂漂js代碼,js購物車代碼

本文目錄一覽:

請問誰有右側漂浮的代碼,是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

(0)
打賞 微信掃一掃 微信掃一掃 支付寶掃一掃 支付寶掃一掃
ZNIV的頭像ZNIV
上一篇 2024-10-04 00:03
下一篇 2024-10-04 00:03

相關推薦

  • JS Proxy(array)用法介紹

    JS Proxy(array)可以說是ES6中非常重要的一個特性,它可以代理一個數組,監聽數據變化並進行攔截、處理。在實際開發中,使用Proxy(array)可以方便地實現數據的監…

    編程 2025-04-29
  • Python周杰倫代碼用法介紹

    本文將從多個方面對Python周杰倫代碼進行詳細的闡述。 一、代碼介紹 from urllib.request import urlopen from bs4 import Bea…

    編程 2025-04-29
  • Python字元串寬度不限制怎麼打代碼

    本文將為大家詳細介紹Python字元串寬度不限制時如何打代碼的幾個方面。 一、保持代碼風格的統一 在Python字元串寬度不限制的情況下,我們可以寫出很長很長的一行代碼。但是,為了…

    編程 2025-04-29
  • Python基礎代碼用法介紹

    本文將從多個方面對Python基礎代碼進行解析和詳細闡述,力求讓讀者深刻理解Python基礎代碼。通過本文的學習,相信大家對Python的學習和應用會更加輕鬆和高效。 一、變數和數…

    編程 2025-04-29
  • Python滿天星代碼:讓編程變得更加簡單

    本文將從多個方面詳細闡述Python滿天星代碼,為大家介紹它的優點以及如何在編程中使用。無論是剛剛接觸編程還是資深程序員,都能從中獲得一定的收穫。 一、簡介 Python滿天星代碼…

    編程 2025-04-29
  • 倉庫管理系統代碼設計Python

    這篇文章將詳細探討如何設計一個基於Python的倉庫管理系統。 一、基本需求 在著手設計之前,我們首先需要確定倉庫管理系統的基本需求。 我們可以將需求分為以下幾個方面: 1、庫存管…

    編程 2025-04-29
  • 寫代碼新手教程

    本文將從語言選擇、學習方法、編碼規範以及常見問題解答等多個方面,為編程新手提供實用、簡明的教程。 一、語言選擇 作為編程新手,選擇一門編程語言是很關鍵的一步。以下是幾個有代表性的編…

    編程 2025-04-29
  • Python購物車程序

    Python購物車程序是一款基於Python編程語言開發的程序,可以實現購物車的相關功能,包括商品的添加、購買、刪除、統計等。 一、添加商品 添加商品是購物車程序的基礎功能之一,用…

    編程 2025-04-29
  • Python實現簡易心形代碼

    在這個文章中,我們將會介紹如何用Python語言編寫一個非常簡單的代碼來生成一個心形圖案。我們將會從安裝Python開始介紹,逐步深入了解如何實現這一任務。 一、安裝Python …

    編程 2025-04-29
  • 怎麼寫不影響Python運行的長段代碼

    在Python編程的過程中,我們不可避免地需要編寫一些長段代碼,包括函數、類、複雜的控制語句等等。在編寫這些代碼時,我們需要考慮代碼可讀性、易用性以及對Python運行性能的影響。…

    編程 2025-04-29

發表回復

登錄後才能評論