本文介绍了使用CSS3过渡来动画化jQueryUI Sortable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用CSS3转换(或任何其他方法)使更像在iOS中列表重新排序,其中列表项目在拖动时平滑地动画,所以在拖动时项目会匆匆拖曳。

How can I use CSS3 transitions (or any other means) to make a jQuery Sortable act more like the list re-ordering in iOS, where list items smoothly animate while dragging, so items scurry out of the way as you drag?

推荐答案

显示了如何使用。物品在你拖动的时候匆匆走出来。它使用,效果正是我要找的。很酷。

https://gist.github.com/801570 shows how to smoothly animate dragging using jQuery Sortable. Items scurry out of the way as you drag. It uses CSS3 Transitions and the effect was exactly what I am looking for. Very cool.

以下是代码:

JSFIDDLE:

HTML

<style name="impostor_size">
    .marker + li { border-top-width:0px; }
</style>
<ul>
    <li>1</li>
    <li>2</li>
    <li>3</li>
    <li>4</li>
    <li>5</li>
    <li>6</li>
</ul>

CSS

body { color:white; font-family:Helvetica, sans-serif;  padding: 10px}
ul { float:left; width:300px; overflow:hidden; border-radius:6px; }
li { display:block; position:relative; padding:12px 6px; z-index:1; margin:5px 20px; }
li:after { background:#18629D; display:block; position:absolute; height:100%; width:100%; top:0px; left:0px; content:' '; border-radius:6px; z-index:-1; }
li { -moz-transition:border-top-width 0.1s ease-in; -webkit-transition:border-top-width 0.1s ease-in; border-top:0px solid rgba(0,0,0,0); }
.marker { opacity:0.0; }

脚本:

var stylesheet = $('style[name=impostor_size]')[0].sheet;
var rule = stylesheet.rules ? stylesheet.rules[0].style : stylesheet.cssRules[0].style;
var setPadding = function(atHeight) {
    rule.cssText = 'border-top-width: '+atHeight+'px'; 
};
$('ul').sortable({
    'placeholder':'marker',
    'start':function(ev, ui) {
        setPadding(ui.item.height());
    },
    'stop':function(ev, ui) {
        var next = ui.item.next();
        next.css({'-moz-transition':'none', '-webkit-transition':'none', 'transition':'none'});
        setTimeout(next.css.bind(next, {'-moz-transition':'border-top-width 0.1s ease-in', '-webkit-transition':'border-top-width 0.1s ease-in', 'transition':'border-top-width 0.1s ease-in'}));
    }
});

这篇关于使用CSS3过渡来动画化jQueryUI Sortable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 06:31