变换属性jquery
Transform property jquery
$(document).ready(function(){
$('#space').css({
'-webkit-transform': 'scale(2,3)',
});
$('#space').css({
'-webkit-transform': 'skew(30deg,20deg)',
});
});
CSS
#space{transition:duration:20s;}
使用上面的Jquery,我希望scale属性在前20秒运行,然后skew属性在接下来的20秒运行,但这里它只运行倾斜。我想为下一个语句提供20秒的延迟,但是有其他简单的方法吗?由于
不能使用.delay()
作为CSS属性。相反,您可以尝试使用setInterval()
函数,根据您想要的预定义转换集逐步向元素添加转换。我在这里做了一个小提琴- http://jsfiddle.net/teddyrised/5AqCm/
这个答案是在你最终想要缩放和使元素在最终状态下倾斜的假设下得出的。
让我稍微解释一下我的代码:
$(document).ready(function () {
var $spce = $("#space"),
trsfm = [], // Declare empty array for transforms
delay = 1000, // Set delay in ms
count = 0; // Set iteration count
// Declare a stepwise array where you want the transform to occur
trsfm = ['scale(2,3)', 'skew(30deg,20deg)'];
var timer = window.setInterval(function () {
if(count < trsfm.length) {
// Increase count by 1
count += 1;
// Stepwise addition of transforms
var trsfmStep = trsfm.slice(0, count).join(' ');
$spce.css({
'-moz-transform': trsfmStep,
'-o-transform': trsfmStep,
'-webkit-transform': trsfmStep,
'transform': trsfmStep
});
// Log in the console, just for fun
console.log(trsfmStep);
} else {
// If you have iterated through all the transforms, clear interval
window.clearInterval(timer);
console.log('Timer cleared.');
}
}, delay);
});
我已经定义了延迟,1000ms(当然你可以改变它),并且还使用一个数组来存储你想要应用的所有转换。转换以从左到右的逐步方式应用,从缩放开始,然后到倾斜。
设置定时器,开始计数。每次达到一个间隔时,脚本都会检查您是否已经遍历了转换数组。如果没有,它将通过从开始连接数组中的项来应用变换的逐步添加,但在您所处的任何步骤(使用.slice()
)方法停止:)
相关文章:
- 使用jQuery属性滚动到数据
- 删除具有jQuery属性的li
- Jquery 属性代码到 Javascript 属性代码
- 使用 *= 的 jQuery 属性选择器
- 奇怪的jquery属性添加到IE8中的复选框上
- HTML 使用 JavaScript 添加具有 JQuery 属性的元素
- 如何将 fadeOut jQuery 属性与 Javascript 文本片段一起使用
- 不区分大小写的 jQuery 属性选择器
- IE中的jQuery属性选择器
- JQuery属性总是返回相同的值
- 任务不可能:jQuery属性选择器
- 如何在jquery插件EasyDate中使用jquery属性
- onclick的jquery属性监听器
- 动态生成的HTML代码没有jQuery属性
- 如何将多个变量从函数传递到jquery属性
- 当Ajax.BeginForm时在Internet Explorer 8上添加的jQuery属性
- JQuery 属性通配符 包含分隔的空格
- jQuery属性自动切换
- 当jquery属性选中复选框时,Angular ng-model不更新
- 理解使用#的jQuery属性选择器