我扩展了所jQuery调用的效果,slideRightShow()并slideLeftHide()使用了几个slideUp()与slideDown()下面相同的函数.但是,我也想实施slideLeftShow()和slideRightHide().
我知道有大量的库提供这种类型的东西(我想避免添加另一大组javascript文件),但任何人都可以提供一个简单的例子来说明如何实现slideLeftShow()或slideRightHide()?
jQuery.fn.extend({
slideRightShow: function() {
return this.each(function() {
jQuery(this).animate({width: 'show'});
});
},
slideLeftHide: function() {
return this.each(function() {
jQuery(this).animate({width: 'hide'});
});
},
slideRightHide: function() {
return this.each(function() {
???
});
},
slideLeftShow: function() {
return this.each(function() {
???
});
}
});
Run Code Online (Sandbox Code Playgroud)
上述slideRightShow功能从左侧开始显示图像,并向右侧前进. 我正在寻找一些方法来做同样的事情,但从右侧开始向左进展.谢谢!
编辑
jQuery接口有我需要的东西(我基本上需要他们的"向右滑动"和"向左滑出"功能),但我无法使用jQuery 1.3:http://interface.eyecon.ro/demos /ifx.html.此外,他们的演示似乎已经破解,并且在投掷一百万个错误之前它只会执行一次幻灯片.
ben*_*wey 184
此功能作为jquery ui http://docs.jquery.com/UI/Effects/Slide的一部分包含在内,如果您想使用自己的名称扩展它,可以使用它.
jQuery.fn.extend({
slideRightShow: function() {
return this.each(function() {
$(this).show('slide', {direction: 'right'}, 1000);
});
},
slideLeftHide: function() {
return this.each(function() {
$(this).hide('slide', {direction: 'left'}, 1000);
});
},
slideRightHide: function() {
return this.each(function() {
$(this).hide('slide', {direction: 'right'}, 1000);
});
},
slideLeftShow: function() {
return this.each(function() {
$(this).show('slide', {direction: 'left'}, 1000);
});
}
});
Run Code Online (Sandbox Code Playgroud)
你需要以下参考资料
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script src="http://jquery-ui.googlecode.com/svn/tags/latest/ui/jquery.effects.core.js"></script>
<script src="http://jquery-ui.googlecode.com/svn/tags/latest/ui/jquery.effects.slide.js"></script>
Run Code Online (Sandbox Code Playgroud)
vdb*_*oor 33
不要忘记填充和边距......
jQuery.fn.slideLeftHide = function(speed, callback) {
this.animate({
width: "hide",
paddingLeft: "hide",
paddingRight: "hide",
marginLeft: "hide",
marginRight: "hide"
}, speed, callback);
}
jQuery.fn.slideLeftShow = function(speed, callback) {
this.animate({
width: "show",
paddingLeft: "show",
paddingRight: "show",
marginLeft: "show",
marginRight: "show"
}, speed, callback);
}
Run Code Online (Sandbox Code Playgroud)
随着投入速度/回调参数,它是一个完整的简易替换为slideUp()和slideDown().
小智 9
您可以通过在自己的脚本文件中添加这些行来为jQuery库添加新功能,并且可以轻松使用fadeSlideRight()和fadeSlideLeft().
注意:您可以根据喜欢的750px实例更改动画的宽度.
$.fn.fadeSlideRight = function(speed,fn) {
return $(this).animate({
'opacity' : 1,
'width' : '750px'
},speed || 400, function() {
$.isFunction(fn) && fn.call(this);
});
}
$.fn.fadeSlideLeft = function(speed,fn) {
return $(this).animate({
'opacity' : 0,
'width' : '0px'
},speed || 400,function() {
$.isFunction(fn) && fn.call(this);
});
}
Run Code Online (Sandbox Code Playgroud)
如果你想改变速度并包含回调,只需像这样添加它们:
jQuery.fn.extend({
slideRightShow: function(speed,callback) {
return this.each(function() {
$(this).show('slide', {direction: 'right'}, speed, callback);
});
},
slideLeftHide: function(speed,callback) {
return this.each(function() {
$(this).hide('slide', {direction: 'left'}, speed, callback);
});
},
slideRightHide: function(speed,callback) {
return this.each(function() {
$(this).hide('slide', {direction: 'right'}, speed, callback);
});
},
slideLeftShow: function(speed,callback) {
return this.each(function() {
$(this).show('slide', {direction: 'left'}, speed, callback);
});
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
380126 次 |
| 最近记录: |