首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在jQuery replaceWith中滑动元素?

如何在jQuery replaceWith中滑动元素?
EN

Stack Overflow用户
提问于 2016-11-27 04:13:13
回答 1查看 73关注 0票数 0

在我的jquery响应中有这样的内容:

代码语言:javascript
运行
复制
...
      success: function(data) {
        $(".headline").replaceWith(function() {
          return $(data).hide().fadeIn();
      });

data是什么样的:<h3 id="5" class="headline-content">Some headline </h3>,我想知道如何滑动数据,使其看起来是从左边进入的?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-11-27 04:31:00

此解决方案使用JQuery和JQuery UI (用于幻灯片左边效果)。在这里,function test(data)将是您的成功函数。replaceWith是不必要的。

代码语言:javascript
运行
复制
var d = "<h3>Some headline </h3>";
test(d);

function test(data) {
    // Inject the result into the DOM element, but hide it at the same time
    $(".headline").hide().html(data);

    // toggle the visibility and animate the element coming in from the right
    $(".headline").toggle( "slide", {direction: "right"});
}
代码语言:javascript
运行
复制
.headline { font-size:2em; 
    width: 300px;
    height: 2em;
    background: #ccc;
}
代码语言:javascript
运行
复制
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type = "text/javascript" 
         src = "https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/jquery-ui.min.js"></script>
<div class="headline"></div>

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40825689

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档