这种js现在用的很多。同时网上的js代码页很多。我直接从网上当了一个来用;代码如下:

html

<div class="bannerbox">
                <div id="focus">
                    <ul>
                        <li><a href="#" target="_blank">
                            <img src="../images/index_18.gif" alt="" /></a></li>
                        <li><a href="#" target="_blank">
                            <img src="../images/index_18.gif" alt="" /></a></li>
                        <li><a href="#" target="_blank">
                            <img src="../images/index_18.gif" alt="" /></a></li>
                        <li><a href="#" target="_blank">
                            <img src="../images/index_18.gif" alt="" /></a></li>
                    </ul>
                </div>
            </div>

css:

.bannerbox { width: 970px; height: 447px; overflow: hidden; margin: 0px auto; }
#focus { border:none;width: 970px; height: 447px; clear: both; overflow: hidden; position: relative; float: left;z-index: 10 }
#focus ul { width: 970px; height: 447px; float: left; position: absolute; clear: both; padding: 0px; margin: 0px; border: none}
#focus ul li { float: left; width: 970px; height: 447px; overflow: hidden; position: relative; padding: 0px; margin:0;border: none }
#focus .preNext { width: 550px; height: 440px; position: absolute; top: 2px; cursor: pointer;border: none;}
#focus .pre { left: 0; background: url(../images/sprite.png) no-repeat left center;z-index: 20;border: none; }
#focus .next { right: 0; background: url(../images/sprite1.png) no-repeat right center;z-index: 20;border: none; }

jquery:

$(function () {
    var sWidth = $("#focus").width();
    var len = $("#focus ul li").length;
    var index = 0;
    var picTimer;
    var btn = "<div class='btnBg'></div><div class='btn'>";
    for (var i = 0; i < len; i++) {
        btn += "<span></span>";
    }
    btn += "</div><div class='preNext pre'></div><div class='preNext next'></div>";
    $("#focus").append(btn);
    $("#focus .btnBg").css("opacity", 0);
    $("#focus .btn span").css("opacity", 0.4).mouseenter(function () {
        index = $("#focus .btn span").index(this);
        showPics(index);
    }).eq(0).trigger("mouseenter");
    $("#focus .preNext").css("opacity", 0.0).hover(function () {
        $(this).stop(true, false).animate({ "opacity": "0.5" }, 300);
    }, function () {
        $(this).stop(true, false).animate({ "opacity": "0" }, 300);
    });
    $("#focus .pre").click(function () {
        index -= 1;
        if (index == -1) { index = len - 1; }
        showPics(index);
    });
    $("#focus .next").click(function () {
        index += 1;
        if (index == len) { index = 0; }
        showPics(index);
    });
    $("#focus ul").css("width", sWidth * (len));
    $("#focus").hover(function () {
        clearInterval(picTimer);
    }, function () {
        picTimer = setInterval(function () {
            showPics(index);
            index++;
            if (index == len) { index = 0; }
        }, 2800);
    }).trigger("mouseleave");
    function showPics(index) {
        var nowLeft = -index * sWidth;
        $("#focus ul").stop(true, false).animate({ "left": nowLeft }, 300);
        $("#focus .btn span").stop(true, false).animate({ "opacity": "0.4" }, 300).eq(index).stop(true, false).animate({ "opacity": "1" }, 300);
    }
});

以上代码经测试在ie9以上,ff,chroom下运行正常。代码参考懒人图库

jquery控制图片切换的更多相关文章

  1. 18款 非常实用 jquery幻灯片图片切换

    1.jquery图片滚动仿QQ商城带左右按钮控制焦点图片切换滚动 jquery图片特效制作仿腾讯QQ商城首页banner焦点图片轮播切换效果,带索引按钮控制和左右按钮控制图片切换. 查看演示>& ...

  2. jquery实现图片切换和js实现图片切换

    jquery实现图片切换: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http ...

  3. Jquery实现图片切换效果(IE,FF,Goole)都可以正常运行

    这里先对标签的样式进行设置(我这里只用了3张图片,可以根据自己的情况,添加) <style type="text/css"> /*展示图片切换的div样式*/ #Sho ...

  4. JS/JQuery控制图片宽度

    function changeImgWidth(){ for (i = 0; i <$('#info img').length; i++) { var imgWidth=$('#info img ...

  5. jquery实现图片切换

    <div> <img class="imgclick" src="img/pic1.png" /> </div> <s ...

  6. jquery 手机 图片切换 例子 网址

    http://m.swdhy.com/page/ShowCompany.aspx?cid=388481&name=山东潍坊金城服装有限公司

  7. 一款基于jQuery的图片分组切换焦点图插件

    这是一款基于jQuery的图片切换焦点图插件,这款jQuery焦点图插件的特点是图片可以分组切换,也就是说一次可以切换多张图片,相比其他焦点图插件,它能节省更多的空间,可以向用户展示更多的图片,非常实 ...

  8. jquery 图片切换

    仿着写的一个jquery的图片切换小插件,代码如下: html: <!DOCTYPE html> <html lang="en"> <head> ...

  9. uwp 图片切换动画

    最近在学习安卓,LOL自定义战绩项目近乎停工,而且腾旭把界面全改了,好烦.刚好学习到安卓中的图片切换动画,我就想在LOL项目中实现一个.首先上百度查看一下,妈的,资料少的可怜. 还是自己来吧.自定义控 ...

随机推荐

  1. PHP文本的读写

    <?php $txtPart="test0.txt"; //export $txtPartContent=fopen($txtPart,"r"); //读 ...

  2. 关于利用input的file属性在页面添加图片的问题

    在页面添加图片涉及到兼容的问题怎么解决兼容问题呢?请看下面分析: 在IE浏览器上面我们能直接通过获取其input的value值来获取其图片的路径. 在火狐和谷歌需要用createObjectURL(( ...

  3. Struts2框架(5)---result结果集

    result结果集 上一篇文章主要讲Struts2框架(4)---Action类访问servlet这篇主要讲result结果集 在Struts.xml中的result元素指的是:指定动作类的动作方法执 ...

  4. Centos 搭建LAMP环境

    1.安装Apache yum install httpd 相关命令: systemctl start httpd.service #启动apache systemctl stop httpd.serv ...

  5. 【转】Lucene.NET详细使用与优化详解

    1 lucene简介1.1 什么是luceneLucene是一个全文搜索框架,而不是应用产品.因此它并不像www.baidu.com 或者google Desktop那么拿来就能用,它只是提供了一种工 ...

  6. KVC与KVO理解

    转载:https://magicalboy.com/kvc_and_kvo/ KVC 与 KVO 理解 KVC 与 KVO 是 Objective C 的关键概念,个人认为必须理解的东西,下面是实例讲 ...

  7. yii2.0使用之缓存

    1.片段缓存(针对于视图中的某部分进行缓存): <?php 设置有效时间 $time=15; 缓存依赖,存入文件.当文件内容发生改变是才会刷新新内容 $dependecy=[ 'class'=& ...

  8. SQL Server从远程服务器导入数据

    语法 insert inot user select * from opendatasource('sqloledb','server=192.168.0.1;uid=sa;pwd=dbpasswor ...

  9. 把GIF背景变透明

    准备软件: 1.Ps cs4 2.QuickTime Player 7.74 开始: 1. 2.弹出文件选择框,但是发现不能选择GIF格式. 3.没关系,在文件名框输入*.*回车,就发现可以选择GIF ...

  10. html行内元素,块元素,空元素

    行内元素:img    span    input  a  b  br  lable   ; 块元素:dl  dt  dd  div  form  table  li  ol  ul  li  h1- ...