怎么用js做出动态图

 时间:2024-10-25 21:19:53

在网页编程中经常会遇到banner,动态图的场景,这里一起探讨下jQuery的banner插件的使用方法,希望对大家有帮助,请帮忙点赞,谢谢

怎么用js做出动态图

工具/原料

记事本

js

浏览器

方法/步骤

1、第一步创建一个HTML,准备好相关的banner的图片素材:

怎么用js做出动态图

2、第二步这里准备四张图片,需要在banner中展示:

怎么用js做出动态图

3、第三步HTML中的css相关代码:<styletype="text/cs衡痕贤伎s">#banner{po霜杼厮贿sition:relative;width:478px;height:286px;border:1pxsolid#666;overflow:hidden;}#banner_listimg{border:0px;}#banner_bg{position:absolute;bottom:0;background-color:#000;height:30px;filter:Alpha(Opacity=30);opacity:0.3;z-index:1000;cursor:pointer;width:478px;}#banner_info{position:absolute;bottom:0;left:5px;height:22px;color:#fff;z-index:1001;cursor:pointer}#banner_text{position:absolute;width:120px;z-index:1002;right:3px;bottom:3px;}#bannerul{position:absolute;list-style-type:none;filter:Alpha(Opacity=80);opacity:0.8;z-index:1002;margin:0;padding:0;bottom:3px;right:5px;}#bannerulli{padding:0px8px;float:left;display:block;color:#FFF;background:#6f4f67;cursor:pointer;border:1pxsolid#333;}#bannerulli.on{background-color:#000;}#banner_lista{position:absolute;}<!--让四张图片都可以重叠在一起--></style>

怎么用js做出动态图

4、第四步这里贴出来,js的相关代码:<scripttype="text/j瞢铍库祢avasc鸡堕樱陨ript">vart=n=0,count;$(document).ready(function(){count=$("#banner_lista").length;$("#banner_lista:not(:first-child)").hide();$("#banner_info").html($("#banner_lista:first-child").find("img").attr('alt'));$("#banner_info").click(function(){window.open($("#banner_lista:first-child").attr('href'),"_blank")});$("#bannerli").click(function(){vari=$(this).text()-1;//获取Li元素内的值,即1,2,3,4n=i;if(i>=count)return;$("#banner_info").html($("#banner_lista").eq(i).find("img").attr('alt'));$("#banner_info").unbind().click(function(){window.open($("#banner_lista").eq(i).attr('href'),"_blank")}); $("#banner_lista").filter(":visible").fadeOut(500).parent().children().eq(i).fadeIn(1000);document.getElementById("banner").style.background="";$(this).toggleClass("on");$(this).siblings().removeAttr("class");});t=setInterval("showAuto()",4000);$("#banner").hover(function(){clearInterval(t)},function(){t=setInterval("showAuto()",4000);});})functionshowAuto(){n=n>=(count-1)?0:++n;$("#bannerli").eq(n).trigger('click');}</script>

怎么用js做出动态图

5、第五步测试看效果:

怎么用js做出动态图

怎么用js做出动态图

js中如何修改html属性 css属性 用UL+LI+CSS制作横排导航 怎么用js在span里添加一张图片 diiv标签怎样居中导航条 html,如何简单快捷,创建一个折叠面板?
热门搜索
少女幻葬 闹钟图片 动漫插画图片 火烧云图片 冰激凌图片