jQuery"$(...).效果不是函数"

men*_*net 13 javascript jquery function effect

我已经在论坛中搜索了但是我找不到任何方法来解决我在jQuery中使用"效果"函数的问题.

TypeError: $(...).effect is not a function在代码中得到了完全错误:

$('div.step').removeClass('active');
$("div.step").effect('slide', {direction: 'right', mode: 'hide'}, 500);
$('#step' + step + '').addClass('active');
$('#step' + step + '').effect('slide', {direction: 'right', mode: 'show'}, 500);
Run Code Online (Sandbox Code Playgroud)

我在这里包含了jQuery和jQuery UI <head></head>:

<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
Run Code Online (Sandbox Code Playgroud)

但是徒劳,你有什么想法吗?谢谢

Jam*_*lly 8

您需要将自定义脚本放在jQuery和jQuery UI声明之后,并将其包装在文档ready()函数中:

<body>
    ...
    <script src="http://code.jquery.com/jquery-1.10.2.js"></script>
    <script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
    <script type="text/javascript">
        $(document).ready(function() {
            ...
        });
    </script>
</body>
Run Code Online (Sandbox Code Playgroud)


小智 7

添加 jQueryUI 不仅仅是 jQuery。jQuery 不包含该effect()函数: https: //code.jquery.com/ui


JCO*_*CO9 5

我不知道问题是否已解决,但我找到了一种使用动画功能复制摇动功能的方法,它的工作原理非常棒:

function shake() {
        var div = document.getElementById('yourElementID');
        var interval = 100;
        var distance = 10;
        var times = 4;

        $(div).css('position', 'relative');

        for (var iter = 0; iter < (times + 1) ; iter++) {
            $(div).animate({
                left: ((iter % 2 == 0 ? distance : distance * -1))
            }, interval);
        }                                                                                                          
        $(div).animate({ left: 0 }, interval);
    }
Run Code Online (Sandbox Code Playgroud)

此解决方案属于thisSite,所有功劳归于他们。我希望这对将来的某人有用,如果有,请将其标记为解决方案,问候。