1

I was trying to use .effect( "bounce", "slow" ) on a div but three more divs appeared instead. The problem is quite hard to explain in text, so I have included a JSFiddle link at the bottom.

I wasn't sure if it was my code so I copied the entire source directly from the documentation to JSFiddle and got the same result.

http://jsfiddle.net/ryBjh/

Here's the code:

<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>effect demo</title>
    <link rel="stylesheet" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css">
    <style>
    div {
        width: 100px;
        height: 100px;
        background: #ccc;
        border: 1px solid #000;
    }
    </style>
    <script src="http://code.jquery.com/jquery-1.8.3.js"></script>
    <script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
</head>
<body>

<p>Click anywhere to apply the effect.</p>
<div></div>

<script>
$( document ).click(function() {
    $( "div" ).effect( "bounce", "slow" );
});
</script>

</body>
</html>

Tested on Chrome Script works normally on ie8 and firefox... so is this a chrome bug?

4

1 回答 1

0

显然 chrome 在页面中添加了额外的 div,然后将 css 样式和动画应用于所有 div 元素。看起来只有 1 个 div,但浏览器插入了几个它自己的。

我更改了代码,因此它只会影响 .box 类,并且一切都按预期工作。

以下是适用于所有浏览器的新代码:

<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>effect demo</title>
    <link rel="stylesheet" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css">
    <style>
   .box {
        width: 100px;
        height: 100px;
        background: #ccc;
        border: 1px solid #000;
    }
    </style>
    <script src="http://code.jquery.com/jquery-1.8.3.js"></script>
    <script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
</head>
<body>

<p>Click anywhere to apply the effect.</p>
<div class= 'box' ></div>

<script>
$( document ).click(function() {
    $( ".box" ).effect( "bounce", "slow" );
});
</script>

</body>
</html>​
于 2012-12-04T16:38:36.077 回答