我需要做一个插件,将生效的用户选择
I need to make a plugin that will take effect the user chooses
我正在开发一个jquery插件,我遇到的问题是,当尝试通过设置时,我尝试设置的三个选项中的两个工作。当我想通过"淡出"效果不显示我任何东西,并停止工作。这是我的代码:
// JavaScript Document
jQuery.fn.slider = function(opciones) {
var configuracion = {
efecto: "fadeIn",
velocidadEfecto: 1000,
tiempoPausa: 3000
}
jQuery.extend(configuracion, opciones);
this.each(function() {
elem = $(this);
elem.find('div:gt(0)').hide();
//$('#imagenes div:gt(0)').hide();
setInterval(function() {
elem.find('div:first-child').fadeOut(0)
.next('div')[configuracion.efecto](configuracion.velocidadEfecto)
.end().appendTo('#imagenes');
}, configuracion.tiempoPausa);
});
return this;
};
#imagenes {
width: 200px;
height: 200px;
border: 1px solid grey;
position: relative;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sin título</title>
<script type="text/javascript">
$(document).ready(function() {
$("#imagenes").slider({
efecto: "slideUp",
velocidadEfecto: 2000,
tiempoPausa: 4000
})
});
</script>
</head>
<body>
<h2>Slider</h2>
<div id="imagenes">
<div>
<img src="http://www.bizreport.com/2011/02/03/android-logo-200x200.jpg" id="foto1" />
</div>
<div>
<img src="http://davidnaylor.org/temp/firefox-logo-200x200.png" id="foto2" />
</div>
<div>
<img src="http://tech21info.com/admin/wp-content/uploads/2013/03/chrome-logo-200x200.png" id="foto3" />
</div>
</div>
</body>
</html>
我不明白为什么"slideUp"效果不起作用。谢谢你!
问候!: -)
您可以通过字符串名称引用方法和属性,例如您的示例中的"fadeIn",但您必须使用括号[]
符号,而不是点.
setInterval(function() {
elem.find('div:first-child').fadeOut(0)
.next('div')[configuracion.efecto](configuracion.velocidadEfecto)
.end().appendTo('#imagenes');
}, configuracion.tiempoPausa);
如果你不使用括号,Javascript将在next('div')
对象上寻找configuracion
属性,并附带efecto
方法(事实并非如此)。使用括号计算出.next('div')['fadeIn'](configuracion.velocidadEfecto)
,因为configuracion.efecto
被求值为它的字符串值。
相关文章:
- d3基于用户选择动态更新节点
- 是否可以仅通过jQuery将图像替换为用户动态选择的另一个图像
- 获取用户选择的不带时区的日期
- 如何使用javascript localStorage保存用户选择并在不同的html页面中显示
- 根据用户从下拉列表中的选择显示多个文本框
- 根据部门用户的选择,接收来自多个电子邮件地址的Wordpress Contactform7查询
- 计算用户从多个文件中选择的选项数量
- jQuery根据用户选择启用/禁用asp.net控件
- 谷歌表单-根据分配给谷歌应用程序的工作为商业用户预先填充多项选择列表
- 将用户对样式表的选择保存在cookie中
- 浏览并选择用户硬盘驱动器中的文件在IE中未定义
- 从下拉框中选择用户信息,并使用进度计数器显示数据库中的选定项目
- 如何使用可点击按钮在Datepicker日历中选择用户在其他月份的当前日期
- 如何在HTML5中选择用户媒体输入
- 自定义选择下拉,无法选择用户添加的项目
- 如何增加/减少'选择'用户想要选择一个选项后的选项宽度
- 从列表中选择用户
- 想要从更改cakephp部门的下拉列表中选择用户
- 如何选择用户从跨度列表在javascript
- 如何在Knockout中的数据绑定选项中自动选择用户状态