首页 > 编程知识 正文

仿淘宝商城伸缩js广告代码的简单介绍

时间:2024-04-24 11:43:24 阅读:334230 作者:QTSJ

本文目录一览:

怎么制作网页中图片转换,就是一幅一幅的显示,跟淘宝网的商品展示一样,用到JS代码,代码怎么编写?

你可以存有 X 张图片,名字差不多,(类似于imp1.jpg,imp2.jpg……impX.jpg)

然后通过定时器 定时改变imp标签里的src属性:js如下

var i =1;

funcition setSrc(){

if(i = X){ // 这里X是你 图片的数量

i =1 ;

}

var srcStr = "imp" + i +"jpg"; // 嗯,这里 i 不知道有没有问题,希望没有,

// 有的话,我想楼主也能轻易解决的

document.getElementById("impId").src=srcStr; (impId 为imp标签的id属性)

i++;

}

定时器 以下任选一种即可:

setInterval("setSrc()",3000);

setTimeout("setSrc()",3000); //需要函数触发

//如 放置在 body 的 onload事件里面

希望对你有帮助

求一份类似于淘宝首页的右上角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

#msg_win .icos

.icos a

.icos a:hover

#msg_title

#msg_content

/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)

},10);

},

fx: function(a, b, c) {//缓冲计算

var cMath = Math[(a - b) 0 ? "floor": "ceil"],c = c || 0.1;

return function()

},

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

},

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() ,100);

}

},

init: function() {//创建HTML

function $(id) ;

this.win=$('msg_win');

var set=;

for (var Id in set) ;

var me = this;

this.minbtn.onclick = function() ;

this.closebtn.onclick = function() ;

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

js 代码,随页面滚动而滚动的浮动广告效果(带关闭按钮)

随滚动而滚动,css就可以实现,也就是固定在屏幕固定位置,用 position:fixed;即可,关闭按钮可以用document.getElementById('').style.display='none';即可,如

div style="width:500px; height:200px; background-color:#F00;position:fixed;left:100px;top:200px;" id="test"

button onclick="document.getElementById('test').style.display='none';"关闭/button

/div

其中left和top都是相对于屏幕的位置

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。