jquery控制图片切换
这种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控制图片切换的更多相关文章
- 18款 非常实用 jquery幻灯片图片切换
1.jquery图片滚动仿QQ商城带左右按钮控制焦点图片切换滚动 jquery图片特效制作仿腾讯QQ商城首页banner焦点图片轮播切换效果,带索引按钮控制和左右按钮控制图片切换. 查看演示>& ...
- jquery实现图片切换和js实现图片切换
jquery实现图片切换: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http ...
- Jquery实现图片切换效果(IE,FF,Goole)都可以正常运行
这里先对标签的样式进行设置(我这里只用了3张图片,可以根据自己的情况,添加) <style type="text/css"> /*展示图片切换的div样式*/ #Sho ...
- JS/JQuery控制图片宽度
function changeImgWidth(){ for (i = 0; i <$('#info img').length; i++) { var imgWidth=$('#info img ...
- jquery实现图片切换
<div> <img class="imgclick" src="img/pic1.png" /> </div> <s ...
- jquery 手机 图片切换 例子 网址
http://m.swdhy.com/page/ShowCompany.aspx?cid=388481&name=山东潍坊金城服装有限公司
- 一款基于jQuery的图片分组切换焦点图插件
这是一款基于jQuery的图片切换焦点图插件,这款jQuery焦点图插件的特点是图片可以分组切换,也就是说一次可以切换多张图片,相比其他焦点图插件,它能节省更多的空间,可以向用户展示更多的图片,非常实 ...
- jquery 图片切换
仿着写的一个jquery的图片切换小插件,代码如下: html: <!DOCTYPE html> <html lang="en"> <head> ...
- uwp 图片切换动画
最近在学习安卓,LOL自定义战绩项目近乎停工,而且腾旭把界面全改了,好烦.刚好学习到安卓中的图片切换动画,我就想在LOL项目中实现一个.首先上百度查看一下,妈的,资料少的可怜. 还是自己来吧.自定义控 ...
随机推荐
- Robot Framework中经常用的第三方库的安装方法
pip升级:python -m pip install --upgrade pip 一.安装robotframework-selenium2library,相当于python中的selenium ...
- 用DapperExtensions和反射来实现一个通用搜索
前言 搜索功能是一个很常用的功能,当然这个搜索不是指全文检索,是指网站的后台管理系统或ERP系统列表的搜索功能.常见做法一般就是在搜索栏上加上几个常用字段来搜索.代码可能一般这样实现 StringBu ...
- 搭建windows环境下(nginx+mysql+php)开发环境
搭建windows环境下(nginx+mysql+php)开发环境 1. 所需准备应用程序包 1.1 nginx 程序包nginx-1.0.4.zip或其他版本(下载地址: http ...
- Gradle之恋-任务2
由于任务作为Gradle的核心功能模块,多花点精力是值得的,本文继上一篇主要涉及到:任务的执行顺序.为任务添加组和描述.跳过任务.扩展任务属性.定义默认任务. 任务顺序 如果构建(build)不能在清 ...
- [HDOJ2572]终曲
Problem Description 最后的挑战终于到了!站在yifenfei和MM面前的只剩下邪恶的大魔王lemon一人了!战胜他,yifenfei就能顺利救出MM.Yifenfei和魔王lemo ...
- Struts文件下载
/* 文件下载的先决条件 * 1. 在xml配置文件中必须配置一个type="stream"的result, result中不需要填写任何内容 * 2. 在Action中编写一个接 ...
- Java 数值类型以及计算
前段时候写了一个对外提供的接口,其中有一个数值校验的计算.在测试的过程中发现5.6-1.6 != 4,在反复的测试过程中发现double类型的数值为有精度丢失的现象,看来还是基础知识不牢固,所以就在网 ...
- koahub软件市场微信编辑器源码,可下载
管理过公众平台的小伙伴都知道,公众平台最重要的是图文的编辑和发布,由于微信公众平台的图文编辑页面比较简陋,功能和样式的比较少,所以一般都是使用专业的微信图文编辑器,koahub软件市场里有一款专门编辑 ...
- 模态Model视图Push下一个视图(混合跳转)
来自: http://www.cnblogs.com/dingding3w/p/6222626.html 如果没有UINavigationController导航栏页面之间切换是不能实现Push操作的 ...
- c++ string 对象操作
字符串转换大小写如下: #include "stdafx.h" #include <iostream> #include <string> using na ...