JQuery UI 剪辑效果不适用于绝对定位

发布于 2024-10-22 00:53:47 字数 1366 浏览 2 评论 0原文

我有一个绝对定位的图像,我想对其应用 jquery 剪辑效果。但我很难实现预期的行为。

下面我粘贴了我正在尝试的代码。

<!DOCTYPE html>
<html>
<head>
  <script src="http://code.jquery.com/jquery-1.5.js"></script>
  <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.10/jquery-ui.min.js"></script>
  <script>
    $(function() {
        // run the currently selected effect
        function runEffect() {
            // get effect type from 
            var selectedEffect = "clip";

            // most effect types need no options passed by default
            var options = { direction : "vertical" };

            // run the effect
            $( "#effect" ).hide( selectedEffect, options, 500);
                    };      

        // set effect from select menu value
        $( "#t" ).click(function() {
            runEffect();
            return false;
        });

            });
    </script>

</head>
<body>
  <div id="images">
    <img id="effect" src="Google_Maps_Icon.png" style="position:absolute; top:200px; left:200px;"/>
    <a id="t" href="#">click</a>
</div>

</body>
</html>

jquery UI 网站上提到了预期行为: http://jqueryui.com/demos/effect/

有什么想法我该如何实现这一目标?

谢谢 萨希尔

I have an image which absolutely positioned and I would like to apply jquery clip effect on it. But I am having trouble to achiever the expected behavior.

Below I have pasted the code which I am trying.

<!DOCTYPE html>
<html>
<head>
  <script src="http://code.jquery.com/jquery-1.5.js"></script>
  <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.10/jquery-ui.min.js"></script>
  <script>
    $(function() {
        // run the currently selected effect
        function runEffect() {
            // get effect type from 
            var selectedEffect = "clip";

            // most effect types need no options passed by default
            var options = { direction : "vertical" };

            // run the effect
            $( "#effect" ).hide( selectedEffect, options, 500);
                    };      

        // set effect from select menu value
        $( "#t" ).click(function() {
            runEffect();
            return false;
        });

            });
    </script>

</head>
<body>
  <div id="images">
    <img id="effect" src="Google_Maps_Icon.png" style="position:absolute; top:200px; left:200px;"/>
    <a id="t" href="#">click</a>
</div>

</body>
</html>

Expected Behavior is as mentioned on jquery UI website:
http://jqueryui.com/demos/effect/

Any thoughts how can I achieve this ?

Thanks
Sahil

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

樱花细雨 2024-10-29 00:53:47

经过一些测试,我发现它是“top”属性正在发挥作用。解决方法是用另一个元素(例如

)包围 ,并将定位委托给该父元素:

<div style="position:absolute; top:200px; left:200px;">
    <img id="effect" src="http://w.ws.static.wireshark.net/image/wsbadge64.png" />
</div>

After a bit of testing, I found it is the "top" property that is playing up. A workaround is to surround the <img> by another element, e.g. <div>, and delegate the positioning to that parent element:

<div style="position:absolute; top:200px; left:200px;">
    <img id="effect" src="http://w.ws.static.wireshark.net/image/wsbadge64.png" />
</div>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文