//需求:点击左右导航箭头,实现内容的切换

  


//代码如下

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<title>Document</title>

<style type="text/css">

*{

margin: 0;

padding: 0;

}

ul{

list-style: none;

}

.box,.box1{

width: 220px;

overflow: hidden;

position: relative;

height: 200px;

}

ul{

width: 1000px;

position: absolute;

}

ul li{

width: 100px;

height: 200px;

float: left;

background-color: red;

margin-right: 20px;

}

.prev,.next{

position: absolute;

width: 30px;

height: 50px;

text-align: center;

line-height: 50px;

top: 75px;

background-color: rgba(200,200,200,0.4);

color: #333;

text-decoration: none;

/*display: none;*/

}

.prev{

left: 0;

}

.next{

right: 0;

}

</style>

</head>

<body>

<div class="box">

<ul>

<li>1</li>

<li>2</li>

<li>3</li>

<li>4</li>

<li>5</li>

<li>6</li>

</ul>

<a href="#" class="prev">&lt;</a>

<a href="#" class="next">&gt;</a>

</div>

<div class="box1">

<ul>

<li>1</li>

<li>2</li>

<li>3</li>

<li>4</li>

<li>5</li>

<li>6</li>

<li>7</li>

<li>8</li>

<li>9</li>

<li>10</li>

<li>11</li>

<li>12</li>

</ul>

<a href="#" class="prev">&lt;</a>

<a href="#" class="next">&gt;</a>

</div>

<script type="text/javascript" src="jquery.1.11.1.min.js"></script>

<script type="text/javascript">

jQuery.fn.extend({

// count:窗口显示的内容个数

// num:每次切换的内容的个数

// speed:切换完成需要的时间

changeImg:function change(count,num,speed){

// $(this) 调用该方法的jq对象

console.log($(this));

var $ul = $(this).find("ul");

var $li = $(this).find("ul li");

var $prev = $(this).find(".prev");

var $next = $(this).find(".next");

// liWidth,每一个li的宽度(包括margin)

var len = $li.length;

var liWidth =$li.eq(0).outerWidth(true);

$ul.css("width",len*liWidth);

$(this).css("width",count*liWidth-20);

// 当前位于最左侧的li元素的索引

var index = 0;

$next.click(function(){

//原索引加上改变值得到新索引

index+=num;

// 最后一li可以显示的索引为li的长度-窗口显示li的个数

if (index>len-count) {

index=0;

}

$ul.animate({

left:(-1)*index*liWidth,

},speed);

});

$prev.click(function(){

index-=num;

if (index<0) {

index=len-count;

}

$ul.animate({

left:(-1)*index*liWidth,

},speed);

})

}

});

$(".box").changeImg(2,2,2000);

$(".box1").changeImg(4,4,2000);

</script>

</body>

</html>

Jquery制作插件---内容切换的更多相关文章

  1. 一个简单的jquery左右列表内容切换应用

    选中左边某个选项点击添加,即可将选中项添加到右边文本框中,点击选中全部即可将全部选项移到右边,移除按钮功能相同. html代码: <div id="main"> < ...

  2. jQuery上下滑动内容切换选项卡

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. jQuery鼠标悬停内容动画切换效果

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  4. 分享一款页面视差滚动切换jquery.localscroll插件

    今天给大家分享一款页面视差滚动切换jquery.localscroll插件. 滚动鼠标液动条看下页面的切换效果.该插件适用浏览器:IE8.360.FireFox.Chrome.Safari.Opera ...

  5. jquery - 通过点击切换文字内容

    今天要写一个简单的显示/隐藏效果,本以为是挺简单的事儿,没想到还真因为基本功不扎实遇到了问题,这里跟大家分享一下. 百度了很多方法,精简能用的干货实在太少,最后还是通过去查jq的官方api才找到了解决 ...

  6. jquery实现页面内部的内容切换

    html页面 .box-body-1-3 li{ margin: 20px; cursor: pointer;   //实现鼠标放在上面是小手状态 } 点击列表 <div class=" ...

  7. 基于jQuery日历插件制作日历

    这篇文章主要介绍了基于jQuery日历插件制作日历的相关资料,需要的朋友可以参考下 来看下最终效果图吧: 是长得丑了一点,不要吐槽我-.- 首先来说说这个日历主要的制作逻辑吧: ·一个月份最多有31天 ...

  8. jQuery实现页面导航内容定位效果,并支持内容切换

    需求 页面向下滚动时,需要将顶部的搜索栏信息和导航菜单吸顶,并且,搜索栏信息和导航菜单之间可以切换. 效果 https://www.iguopin.com/index.php?m=&c=ind ...

  9. 移动开发必备!15款jQuery Mobile插件

    移动互联网的发展,来自PC端的网页并不能完全自适应移动端页面需求,使得响应式设计体验产生并成为潮流,也正是这样一种需求,促成了jQuery Mobile的流行.jQuery Mobile这样一款基于j ...

随机推荐

  1. 树莓派4B踩坑指南 - (6)安装常用软件及相关设置

    安装软件 安装LibreOffice中文包 sudo apt-get install libreoffice-l10n-zh-cn sudo reboot 安装codeblocks并汉化: sudo ...

  2. Excel实用知识1

    纯手打,可能有错别字,使用的版本是office2013 转载请注明出处 http://www.cnblogs.com/hnnydxgjj/p/6329509.html ,谢谢 使用现成的模板 ”开头的 ...

  3. hdoj6708 2019 CCPC网络选拔赛 1007 Windows Of CCPC

    #include <cstdio> #include <iostream> #include <algorithm> using namespace std; ch ...

  4. win10系统黑屏无法显示桌面解决

    适用情况:win10系统 黑屏无法显示出桌面但是程序能正常运行时 解决方法:win+r 调出运行窗口 运行:Explorer.exe

  5. [转]:Ubuntu 下Apache安装和配置

    [转]:Ubuntu 下Apache安装和配置_服务器应用_Linux公社-Linux系统门户网站  https://www.linuxidc.com/Linux/2013-06/85827.htm ...

  6. springboot不能加载主类

    参考:https://www.cnblogs.com/iyyy/p/8085719.html 若为maven项目:用maven更新下项目.

  7. 学习笔记(2)- BioBERT

    Jinhyuk Lee, Wonjin Yoon, Sungdong Kim, Donghyeon Kim, Sunkyu Kim, Chan Ho So, Jaewoo Kang, BioBERT: ...

  8. eclipse导入项目上面有个红叉X

    问题: 今天突然想到一个以前做过的项目,想导入到新环境中,发现不管咱整都一个红叉X, 我记得以前好像碰到过类似的问题,当时三秒搞定,谁知道时间一长,三分钟没有搞定. 还是记录下: 一般导入项目出错,肯 ...

  9. SRS——打开 stream caster

    按照默认的配置编译启动后,发现 stream caster 不起作用,启动时报如下警告: [-- ::][][] stream caster: off 原因是编译SRS时没有打开StreamCaste ...

  10. UniGUI之ServerModule常用设置(07)

    主要有两个设置,它是一个单独的, 这意味着它只在每个应用程序中创建一次. 它主要用于配置各种服务器设置.不能将组件放在ServerModule上. 如前所述, ServerModule 是一个单一的, ...