本文实例讲述了jQuery css实现的切换图片功能代码。分享给大家供大家参考,具体如下:
运行效果截图如下:
具体代码如下:
<!DOCTYPE html> <html> <head> <title>demo</title> <script type="text/javascript" src="jquery.js"></script> <style type="text/css" > body { margin:0; padding:0; } .container { border:6px solid gray; background:black; width:600px; height:400px; position:relative; left:50%; margin-left:-300px; border-radius:6px; -webkit-border-radius:6px; -moz-border-radius:6px; overflow:hidden; } .text-center { text-align:center; } h1 { font-size:50px; color:gray; font-weight:bolder; } .imgUL { width:100%; height:100%; margin:0px; padding:0px; list-style:none; } .imgUL li { float:left; margin:0px; padding:0px; height:100%; color:gray; font-weight:bolder; text-align:center; font-size:100px; line-height:400px; } .pageUL { position:relative; top:-40px; height:40px; list-style:none; margin:0px; padding:0px; float:right; } .pageUL li { float:left; display:block; width:36px; height:36px; border:2px solid red; margin-left:5px; border-radius:4px; -webkit-border-radius:4px; text-align:center; -moz-border-radius:4px; line-height:36px; color:gray; font-weight:bolder; cursor:pointer; } .pageUL li:hover { background:#5ACF00; color:black; } .pageUL li.active { background:#5ACF00; color:black; } </style> <script type="text/javascript" > $(document).ready(function(){ var autoInterval = null, imgUL = $(".imgUL"), imgliList = imgUL.children("li"), liListLength = imgliList.length, pageUL = $('.pageUL'), pageLiList = pageUL.children('li'), pageLiListLength = pageLiList.length, // initialize activePageLi = $(pageLiList[0]); activePageLi.addClass('active'); imgliList.width(600); imgUL.width(liListLength * 600); $(".pageUL li").mouseover(function(){ mouseoverAnimate(this); }).mouseout(function(){ createInterval(); }); createInterval(); function mouseoverAnimate(_this){ clearInterval(autoInterval); activePageLi.removeClass('active'); activePageLi = $(_this); var pageNo = parseInt(activePageLi.html()); activePageLi.addClass('active'); imgUL.animate({ 'marginLeft': -600 * (pageNo - 1) }, 10); } function createInterval(){ autoInterval = setInterval(function(){ var pageNo = parseInt(activePageLi.html()); pageNo++; if(pageNo > pageLiListLength) { pageNo = 1; } activePageLi.removeClass('active'); activePageLi = $(pageLiList[pageNo - 1]); activePageLi.addClass('active'); imgUL.animate({ 'marginLeft': -600*(pageNo - 1) }, 1100); }, 1500); } }); </script> </head> <body> <h1 id="Demo">Demo</h1> <div class="container" id="container"> <ul class="imgUL"> <li>Page1</li> <li>Page2</li> <li>Page3</li> <li>Page4</li> <li>Page5</li> <li>Page6</li> </ul> <ul class="pageUL"> <li>1</li> <li>2</li> <li>3</li> <li>4</li> <li>5</li> <li>6</li> </ul> </div> </body> </html>
更多关于jQuery特效相关内容感兴趣的读者可查看本站专题:《jQuery常见经典特效汇总》及《jQuery动画与特效用法总结》
希望本文所述对大家jQuery程序设计有所帮助。

实现方法:1、用“$("img").delay(毫秒数).fadeOut()”语句,delay()设置延迟秒数;2、用“setTimeout(function(){ $("img").hide(); },毫秒值);”语句,通过定时器来延迟。

区别:1、axios是一个异步请求框架,用于封装底层的XMLHttpRequest,而jquery是一个JavaScript库,只是顺便封装了dom操作;2、axios是基于承诺对象的,可以用承诺对象中的方法,而jquery不基于承诺对象。

增加元素的方法:1、用append(),语法“$("body").append(新元素)”,可向body内部的末尾处增加元素;2、用prepend(),语法“$("body").prepend(新元素)”,可向body内部的开始处增加元素。

修改方法:1、用css()设置新样式,语法“$(元素).css("min-height","新值")”;2、用attr(),通过设置style属性来添加新样式,语法“$(元素).attr("style","min-height:新值")”。

在jquery中,apply()方法用于改变this指向,使用另一个对象替换当前对象,是应用某一对象的一个方法,语法为“apply(thisobj,[argarray])”;参数argarray表示的是以数组的形式进行传递。

删除方法:1、用empty(),语法“$("div").empty();”,可删除所有子节点和内容;2、用children()和remove(),语法“$("div").children().remove();”,只删除子元素,不删除内容。

去掉方法:1、用“$(selector).removeAttr("readonly")”语句删除readonly属性;2、用“$(selector).attr("readonly",false)”将readonly属性的值设置为false。

on()方法有4个参数:1、第一个参数不可省略,规定要从被选元素添加的一个或多个事件或命名空间;2、第二个参数可省略,规定元素的事件处理程序;3、第三个参数可省略,规定传递到函数的额外数据;4、第四个参数可省略,规定当事件发生时运行的函数。


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

Dreamweaver CS6
视觉化网页开发工具

记事本++7.3.1
好用且免费的代码编辑器

安全考试浏览器
Safe Exam Browser是一个安全的浏览器环境,用于安全地进行在线考试。该软件将任何计算机变成一个安全的工作站。它控制对任何实用工具的访问,并防止学生使用未经授权的资源。

SublimeText3 英文版
推荐:为Win版本,支持代码提示!

ZendStudio 13.5.1 Mac
功能强大的PHP集成开发环境