这篇文章主要介绍了jquery简单实现幻灯片的方法,核心的js代码只有9行即可实现幻灯切换效果,非常简单实用,需要的朋友可以参考下
本文实例讲述了jquery简单实现幻灯片的方法。分享给大家供大家参考。具体如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>幻灯片</title> <script type="text/javascript" src="https://www.jb51.net/js/jquery-1.11.1.min.js"></script> <style type="text/css"> .slide{position: relative; overflow: hidden;} .slide img{max-width: 100%; position: absolute; left: 0; top: 0;} .slide img:first-child{position: relative; visibility: visible;} </style> </head> <body> <div> <img src="https://www.jb51.net/images/172233f3cyzidsc8rl8irz.jpg" /> <img src="https://www.jb51.net/images/172231vxzvzz2xvk92d5m0.jpg" /> <img src="https://www.jb51.net/images/172228jybldywbdwdflfzm.jpg" /> <img src="https://www.jb51.net/images/172223i8otbbsot8b232o5.jpg" /> </div> <script type="text/javascript"> var size = $('.slide img').size(); var _index = size; var timer = null; $('.slide').append($('.slide img:eq(0)').clone()); timer = setInterval(function(){ $('.slide img').eq(_index).fadeOut(800); _index == 1?_index=size:_index--; $('.slide img').eq(_index).fadeIn(800); },4000); </script> </body> </html>
希望本文所述对大家的jquery程序设计有所帮助。
您可能感兴趣的文章: